Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 数组形式的文件内容_C++ - Fatal编程技术网

C++ 数组形式的文件内容

C++ 数组形式的文件内容,c++,C++,我在读取文件内容方面没有问题,但我想以数组格式存储这些值。我怎么做 文件内容: 1,2,4,4,0,30,15,7.6,5 1,2,4,5,0,0,0,0,0 1,3,2,1,0,40,29,14,9.6 1,3,2,2,0,0,19,9.4,6.2 代码: ifstream-infle; infle.open(“test.txt”); if(infle.is_open()) { while(infle.good()) { c

我在读取文件内容方面没有问题,但我想以数组格式存储这些值。我怎么做

文件内容:

1,2,4,4,0,30,15,7.6,5   
1,2,4,5,0,0,0,0,0   
1,3,2,1,0,40,29,14,9.6   
1,3,2,2,0,0,19,9.4,6.2  
代码:

ifstream-infle;
infle.open(“test.txt”);
if(infle.is_open())
{                       
while(infle.good())
{
cout
void解析器()
{
ifstream数据(“test.txt”);
弦线;
矢量parsedRow;
while(getline(数据,行))
{
线状流线状流(线状);
字符串单元;
矢量parsedRow;
while(getline(行流,单元格','))
{
parsedRow.推回(单元);
}
parsedCsv.推回(parsedRow);
}
};
如果需要浮点数组

void parser()
{
    ifstream  data("test.txt");
    string line;
    vector<vector<float>> parsedRow;
    while(getline(data,line))
    {
        stringstream lineStream(line);
        string cell;
        vector<float> parsedRow;
        while(getline(lineStream, cell, ','))
        {
            float f_cell = atof(cell.c_str());
            parsedRow.push_back(f_cell);
        }

        parsedCsv.push_back(parsedRow);
    }
};
void解析器()
{
ifstream数据(“test.txt”);
弦线;
矢量parsedRow;
while(getline(数据,行))
{
线状流线状流(线状);
字符串单元;
矢量parsedRow;
while(getline(行流,单元格','))
{
float f_cell=atof(cell.c_str());
推回(f单元);
}
parsedCsv.推回(parsedRow);
}
};

来源:

什么样的数组格式?嵌套的,所以它是每行一个数组,还是只有一个大数组?它也可以是向量,还是必须是数组?
void parser()
{
    ifstream  data("test.txt");
    string line;
    vector<vector<string>> parsedRow;
    while(getline(data,line))
    {
        stringstream lineStream(line);
        string cell;
        vector<string> parsedRow;
        while(getline(lineStream, cell, ','))
        {
            parsedRow.push_back(cell);
        }

        parsedCsv.push_back(parsedRow);
    }
};
void parser()
{
    ifstream  data("test.txt");
    string line;
    vector<vector<float>> parsedRow;
    while(getline(data,line))
    {
        stringstream lineStream(line);
        string cell;
        vector<float> parsedRow;
        while(getline(lineStream, cell, ','))
        {
            float f_cell = atof(cell.c_str());
            parsedRow.push_back(f_cell);
        }

        parsedCsv.push_back(parsedRow);
    }
};