这是我编写的用于在C ++中以csv格式读取excel文件的代码。我想逐行阅读文件。当我运行代码时,它给我一个错误说
缺少类模板'array'的参数列表
感谢。
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;
int main() {
array<string , 29>arr;
string line;
int location;
int start = 0;
//int arrayFile[51][28] = { { 0 } };
string fileName;
ifstream infile(fileName);
infile >> line;
//error check
if (infile.fail()) {
cout << "File not Found !" << endl;
exit(1);
}
//reading the file
for (int i = 0; i < 29; i++) {
location = line.find(","); //find the first comma in line
array[i] = line.substr(start, location - start); // separate the information from line up to the comma
line = line.substr(location + 1); //change line to the rest after removing the the abouve piece of the information
}
array[i] = line;
答案 0 :(得分:1)
由于您声明了using namespace std
并且包含<array>
,array
不是变量,而是模板类(C ++ 11 STL)。您必须使用它来定义实际数组,如
array<string, 29> arr;
// std::array<std::string, 29> arr;
然后您可以使用arr