【发布时间】:2016-07-16 20:13:11
【问题描述】:
我是 C++ 的初学者,在我的程序开始时,我试图将来自 csv 文件的数据输入到双向量中。
但是,当我尝试运行程序时,我不断收到“行”和“列”未在此范围内声明。
我试图通过放置 ' int row; 来解决这个问题。国际单位; '上面'字符串输入[row][col];'尝试解决问题。
但后来我得到错误“数组绑定不是']'标记之前的整数常量”。
我想知道如何解决这个问题?或者,如果有一些我没有意识到的遗漏。
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
string input[row][col];
const int ROW = 10;
const int COL = 4;
string input[ROW][COL];
const string datatable = "table2.csv";
string line;
int col = 0;
int row = 0;
void readCSV() ////this is the function to read the file
{
ifstream file(datatable); ///opens file
while (getline(file, line))
{
istringstream iss(line); //takes out white
string result;
while (getline(iss, result, ','))
{
input[row][col] = result; // creates string for element
col = col + 1;
}
row = row + 1;
col = 0;
}
【问题讨论】: