非工作代码:问题与ifstream的读取CSV数据
#include<iostream>
#include<fstream>
#include<string>
int main(){
int id; string name;char comma ; double money;
ifstream read("testfile.csv");
while (read >> id >> comma>> name >> comma >> money)
{cout << id <<comma<<name<<comma<<money<< endl ;}
read.close();
_getch();
return 0;}
CSV文件数据&结构:
1,user1,999 2,user2,33 3,user3,337
但是,下面的工作正常。为什么这样?
while (read >> id >>comma>>name) {cout << id<<comma<<name <<endl ;}
一些很好的阅读:http://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c – NathanOliver
@NathanOliver谢谢,正试图找出为什么替代代码起作用。 – CowardlyDog