我收到一个" conversion from ‘std::string (*)[50]’ to non-scalar type ‘std::string’ requested"错误,似乎无法修复它

I am getting a " conversion from ‘std::string (*)[50]’ to non-scalar type ‘std::string’ requested" error and cant seem to fix it

本文关键字:std string 错误 type requested non-scalar 一个 conversion from to      更新时间:2023-10-16

这是我正在编写的程序的开始。如您所见,它是不完整的,但是我正在检查我的程序是否有错误,但我遇到了这个错误。我查找了它,并找到了解决方案,例如"在调用多功能阵列时不包括括号",我进行了更正并遇到了此错误。关于如何解决的任何建议?

#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<fstream>
using namespace std;
void readEmployees();
void readPasswords();
void mixPasswords(string(*)[50], string[], string(*)[50]);
string employee[50][50];
string passwords[50];
string passwordsAssigned[50][50];
int main()
{
    readEmployees();
    readPasswords();
    mixPasswords(employee, passwords, passwordsAssigned);
    return 0;
}
void readEmployees()
{
    int y;
    ifstream fileInput;
    fileInput.open("employees.txt");
    for(int x = 0; x < 50; x++)
    {
            fileInput >> employee[x][y] >> employee[y][x];
            y++;
    }

}
void readPasswords()
{
    ifstream fileInput;
    fileInput.open("passwords.txt");
    for(int x = 0; x < 50; x++)
    {
            fileInput >> passwords[x];
    }
}
void mixPasswords(string employee(*)[50], string passwords[], string completed(*)[50])
{
}

您的声明void mixPasswords(string, string, string);与您传递给它的参数的类型不匹配。您需要将声明更改为

之类的东西
void mixPasswords(string[][50], string[], string[][50]);

此外,您对mixPasswords的定义不能定义先前声明的函数,因为其参数列表与声明不符。取而代之的是,它声明并定义了采用不同参数的新的,未使用的mixPasswords的过载。您需要使您的声明和定义匹配。