I have the following format. Each line has two integers and the file is ended by “*”. How can I read the two numbers from the file. Thanks.
4 5
7 8
78 89
* //end of file
Edit
I know read the two numbers but do not know how to deal with “*”. If I store each number as integer type and read them by cin. But The last line is a string type. So the problem is that I read it as a integer but it is string, I do not how to judge whether it is * or not.
My code was as follows (it is obviously incorrect):
string strLine,strChar;
istringstream istr;
int a,b;
while(getline(fin,strChar))
{
istr.str(strLine);
istr>> ws;
istr>>strChar;
if (strChar=="*")
{
break;
}
istr>>a>>b;
}
You can simply pull the numbers from the
ifstreamobject until it fails.