#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
//写文件
ofstream outFile; //ofstream outFile("file.csv", ios::app);
outFile.open("file.csv", ios::app); //“file.csv” 文件名; ios::app 末尾追加模式 out/in/...
outFile << "name" <<"," << "age"<<endl;
outFile << "小明" <<"," << 18 << endl;
outFile.close();
//读文件
ifstream inFile("file.csv", ios::in);
string lineStr;
vector<vector<stirng>> strAry;
while(getline(inFile, lineStr))
{
//打印整行字符串
cout << lineStr << endl;
//存成二维表结构
stringstream ss(lineStr);
string str;
vector<string> lineAry;
//按照逗号分隔
while(getline(ss, str, ','))
lineAry.push_back(str);
strAry.push_back(lineAry);
}
getchar();
return 0;
}