I need to write a program that will do several operations for objects delimited with ";" "," and " ," and " ;"
sample csv file:
user;owner;group1;group2;etc.
Michael Beaver,John Dundi, Global, Cracow, NY, Berlin
Dave Sadih, Sarah Flock, Global
Moran Kleih, Rebeca Diaz, Global, berlin, Warsaw, Moscov, Puerto Rico
---> note that the number of columns is diffrent in each row.
and:
I need to write a loop (or sth else) that will take a csv file (like the one above) and process each line that way:
Result:
(text on screen)
Hello Michael Beaver
Your owner is: John Dundi
I am adding You to Global
I am adding You to Cracow,
I am adding You to NY
I am adding you to Berlin
Thanks!
then it should go to the second line of our csv file and do everything like in previous line...The operation should process till the end of the last line in csv file...
Ofcourse the program looks idiotic, but I just want to know the mechanic...
I know how to read the line of file word by word and to put that word as a string...
the main problem for me is to do diffrent operation for first two columns, and diffrent for the rest ones..
{
string c0,c1,c2,c3,c4,plik,zmienna1,zmienna2,line,line1,line2,filename;
string token;
stringstream iss,iss2;
system("cls");
cout << "Add T-users\n";
cout << "----------------------\n";
cout << "Please enter filename: ";
cin >> filename;
ifstream file(filename.c_str());
if (file)
{
while ( getline(file, line) )
{
iss << line;
while ( getline(iss, token, ';') )
{
cout << token << endl;
system ("pause");
}
iss.clear();
}
}
else
czerwony();
cout << "Unable to open file";
bialy();
Sleep(1400);
break;
}
the problem is that my prog use only two delims (end of line, ; ) and I cannot do diffrent things for first 2 objects of every csv line... My program doesnt recognize first and second object of line...
Please Help!