标签:space iostream 命名 ack number file back field cto
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]; } }
标签:space iostream 命名 ack number file back field cto
原文地址:https://www.cnblogs.com/sbj123456789/p/13193709.html