我收到一个" 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
这是我正在编写的程序的开始。如您所见,它是不完整的,但是我正在检查我的程序是否有错误,但我遇到了这个错误。我查找了它,并找到了解决方案,例如"在调用多功能阵列时不包括括号",我进行了更正并遇到了此错误。关于如何解决的任何建议?
#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
的过载。您需要使您的声明和定义匹配。
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- 使用 std::string () const 函数启动线程或未来
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 如何更改大小(std::string)
- std::string 的对象真的可以移动吗?
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号
- std::string 构造函数如何处理固定大小的 char[]?
- 真的没有来自 std::string_view 的 std::string 的显式构造函数吗?
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- 重载 + 自己的类和 std::string 的运算符
- 如何使用 std::string 作为 QHash 的键?
- 将日语 wstring 转换为 std::string
- 可以从std::string继承以提供类型一致性吗
- 构造函数采用std::string_view与std::string并移动
- 在共享缓冲区内存中创建 ::std::string 对象
- std::string.size() 未知行为
- Valgrind 在 std::string::swap 中报告 SIGILL