C++ 尝试通过多个函数移动阵列时遇到了一个错误,我不知道如何修复

C++ 尝试通过多个函数移动阵列时遇到了一个错误,我不知道如何修复,c++,C++,这就是错误 hw4.cpp:16:41:错误:无法将'std::string{aka std::basic_string}'转换为'std::string* {aka std::basic_string}'用于参数'1'到'std::string(std::string)' writepass(随机密码(readpasswords()),readnames()); “代码” #包括 #包括 #包括 #包括 使用名称空间std; 字符串readnames(); 字符串readpasswords()

这就是错误
hw4.cpp:16:41:错误:无法将'std::string{aka std::basic_string}'转换为'std::string* {aka std::basic_string}'用于参数'1'到'std::string(std::string)' writepass(随机密码(readpasswords()),readnames()); “代码”

#包括
#包括
#包括
#包括
使用名称空间std;
字符串readnames();
字符串readpasswords();
字符串密码(字符串[]);
int writepass(字符串[],字符串[][2]);
int main()
{
writepass(随机密码(readpasswords()),readnames());
返回0;
}
“功能”

string readnames()
{
字符串名称[100][2];
Iftream indata;
indata.open(“employees.txt”);
int x=0;
而(!indata.eof())
{
indata>>名称[x][0];
indata>>名称[x][1];

不能不要使用像
string[][2]
这样的奇怪类型。对数组使用
std::vector
,对一对
std::string
使用
std::pair
。这是一个如何声明和实现
readnames()
的示例:

std::vector<std::pair<std::string, std::string>> readnames() {
    std::vector<std::pair<std::string, std::string>> names;
    std::ifstream indata("employees.txt");

    while (true) {    // not !indata.eof(), see https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons
        std::pair<std::string, std::string> name;
        if (!(indata >> name.first >> name.second))
            break;
        names.push_back(name);
    }

    return names;
}
std::vector readnames(){
std::矢量名称;
std::ifstream indata(“employees.txt”);
而(true){//not!indata.eof(),请参见https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons
std::对名称;
如果(!(indata>>name.first>>name.second))
打破
名称。推回(名称);
}
返回姓名;
}
其他函数的签名可能是:

std::vector<string> readpasswords();
std::vector<string> randpasswords(const std::vector<string>&);

void writepass(const std::vector<string>&, 
    const std::vector<std::pair<std::string, std::string>>&);
std::vector readpasswords();
std::vector和密码(const std::vector&);
void writepass(const std::vector&、,
常数std::向量&);

不要使用像
string[][2]
这样的奇怪类型。对数组使用
std::vector
,对一对
std::string
使用
std::pair
。这是一个如何声明和实现
readnames()
的示例:

std::vector<std::pair<std::string, std::string>> readnames() {
    std::vector<std::pair<std::string, std::string>> names;
    std::ifstream indata("employees.txt");

    while (true) {    // not !indata.eof(), see https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons
        std::pair<std::string, std::string> name;
        if (!(indata >> name.first >> name.second))
            break;
        names.push_back(name);
    }

    return names;
}
std::vector readnames(){
std::矢量名称;
std::ifstream indata(“employees.txt”);
而(true){//not!indata.eof(),请参见https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons
std::对名称;
如果(!(indata>>name.first>>name.second))
打破
名称。推回(名称);
}
返回姓名;
}
其他函数的签名可能是:

std::vector<string> readpasswords();
std::vector<string> randpasswords(const std::vector<string>&);

void writepass(const std::vector<string>&, 
    const std::vector<std::pair<std::string, std::string>>&);
std::vector readpasswords();
std::vector和密码(const std::vector&);
void writepass(const std::vector&、,
常数std::向量&);

randpasswords()
返回
string
writepass(…)
接受
string[]
,它分解为
string*
string*
是不同的类型。因此,我将类型声明为string*readpasswords(),而不是string readpasswords()如果需要字符串数组,请使用
std::vector
。建议阅读:您尝试了什么?
randpasswords()
返回
string
writepass(…)
获取
string[]
分解为
string*
string
string*
是不同的类型。因此,我要将类型声明为string*readpasswords()而不是string readpasswords()如果您需要字符串数组,请使用
std::vector
。建议阅读:您尝试了什么?如何像使用array@AaronBrethower,为什么需要声明大小?
std::vector
是一个动态数组,可以使用
.size()获取其大小
member函数。如何像使用array@AaronBrethower,为什么需要声明大小?
std::vector
是一个动态数组,可以使用
.size()
成员函数获取其大小。