C++读取csv文件

C++读取csv文件,采用文件流的方法,用到了getline函数(带有自动分隔功能)

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
 
using namespace std; //注意,命名空间 std

int main()
{
    ifstream infile("Test.csv");
    string line;
    getline(infile, line);
    while (getline(infile, line))
    {
        istringstream sin(line);
        vector<string> fields;
        string field;
        while (getline(sin, field, ',')) 
        {
            fields.push_back(field);
        }
        string number = fields[0];
        string project_name = fields[1];
    }
}

 

posted @ 2020-06-26 02:58  sbj123456789  阅读(5880)  评论(0编辑  收藏  举报