Non-working code:
#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;}
The csv file data & structure:
1,user1,999
2,user2,33
3,user3,337
But, the following works fine. Why so?
while (read >> id >>comma>>name)
{cout << id<<comma<<name <<endl ;}