Hello all.
I'm trying to read a line of data in from a csv file and then assign the fields to it to an int w, string y, and double z **See code below**
However, I have two problems:
1. The first is in reading in the all contents of the second field and assigning it to a string y WITH white-space included. If I compile this code it will only output the first word in the second field even with the noskipws **line 36**
2. The second is reading in the complete number with both decimal places (only the 12 shows) and assigning it to a double z **lin 42**
For simplicity sake the contents of file "clients.txt" read are:
503,long meadow,12.29
But the output to screen is:
503 long 12
#include <cstdlib>
#include <fstream>
#include <ios>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int w;
string word;
string y;
double z;
ifstream infile("clients.txt");
while (getline( infile, word ))
{
if (word.empty()) continue;
istringstream ss( word );
{ string val;
getline( ss, val, ',' );
stringstream( val ) >> w;
cout<<" "<<w<<" ";
}
{ string val;
getline(ss,val, ',' );
stringstream( val )>>noskipws>> y;
cout<<y<<" ";
}
{ string val;
getline( ss, val, ',' );
stringstream( val ) >> z;
cout<<z<<endl;
}
}
system("PAUSE");
return 0;
}