//I know it is bad using (namespace std) but I'm editing a "attached project"
// as exercise from my Professor.
//All required libraries: iostream, fstream, sstream, stdlib are included.
stringstream stringas;
ifstream fromfile;
string nickname;
float points;
nickname="";
points=0;
fromfile.open ("top10.txt", ifstream::in);
cout << "Testing contents from file : " << endl;
while (fromfile.good()){
if((char) fromfile.get() != '|' )
{
fromfile.unget();
stringas << (char) fromfile.get();
}
else
{
if(nickname=="")
{
nickname = stringas.str();
//or i want use stringas >> nickname;
stringas.str(string());
}
else
{
stringas >> points;
//Problem starts here (when I use >> operator)
//then I extract all chars from "ss object"
//Why i can't get Others chars from file when
//while(fromfile.good()) starts again?
stringas.str(string());
cout << "Nickname: " << nome << endl;
cout << "Points: " << points << endl;
topplayers.insert(nickname,points);
//topplayers is a Custom(mine) Linked List of
// struct type {string nicks,float scores} defined in private
// in a class(where there is this function).
}
}
}
fromfile.close();
Help me to understand what is happening when I use >> operator of a stringstream and why I cannot re-use << operator after.
I'm a Italian student, sorry for my bad English.
I know that I can make parsing with delimiters from a file in other ways, but I need a simple way, without using too many variables and library such as Boost.
EDITED FOR MORE DETAILS:
top10.txt file contains:
t04d|120|simon|240|
ouput:
Testing contents from file:
Nickname: t04d
Points: 120
Application run without errors,but obviously don't print on screen
Nickname: simon
Points: 240
That I expected;