【发布时间】:2019-10-29 15:49:43
【问题描述】:
我打开了一个 .csv 文件并将其内容保存到一个二维数组中。当我尝试返回它的值时,我得到了提到的错误。
如果我不使用该函数或不返回数组,一切都会正常工作。最好的方法是什么?
string read_csv()
{
std::ifstream file_csv("C:\\DRT\\Lista de Materiais\\Lista.csv");
string csv_temp[600][40]
while (std::getline(file_csv, temp))
{
j = 1;
while (temp != "")
{
pos = temp.find(",");
csv_temp[i][j] = temp.substr(0, pos);
temp = temp.substr(pos + 1, string::npos);
j = j + 1;
}
i = i + 1;
}
return csv_lista;
}
int main()
{
string csv[600][30];
csv = read_csv();
}
C2440: 'return': 无法从 'std::string [300][30]' 转换为 'std::basic_string,std::allocator>'
【问题讨论】:
-
首先,您的返回类型只是
string,而不是多维字符串数组。其次,您不能在 C++ 中返回 c 样式的数组。 -
如果我没记错的话,您也从未声明过 ´´´csv_lista´´´ 或为其分配任何值。
标签: c++