非工作代碼:問題與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