I am facing a problem please help me !
Dear Friends
I am reading an int and a double from file.
How can I check whetheer the value read is an int or double.
int intval;
double doubleval;
ifstream infile("Data.dat")
infile >> intval >> doubleval;
// how can I check whether intval has got an integer and doubleval has got a double value.
//infile.dat has
2 23.323
what happens if infile.dat has data like this
# &&*********
//so it'll read junk values so how could I check the variables.??
Please help me to overcome this problem!!!
Re: I am facing a problem please help me !
not quite Qt related, right...?
anyway, you should be able to use the fail() function on the stream.
Code:
int anInt;
astream >> anInt;
if (astream.fail()) cerr << "not an int"
of course you have to take care that a float will usually also be accepted as an int, so if you tolerate either, try the float first.
Re: I am facing a problem please help me !
Anyway, if the file is designed yourself or your team, you should know the format of the file.
Re: I am facing a problem please help me !
If the file is made by you, you could constraint data in binary records to retrieve as structs.