HI!
I was wondering how can I do some formatted input in C++?
I mean like in C we write :
1 2
int a , b ;
scanf ("%d.%d" , & a , & b) ;
this piece of code gets the input like a floating point, for example if user inters 12.56 the program gives 12 as an integer to a and 56 as an integer to b ;
I was wondering how can I do such a thing in C++?
The only thing I could think of was this :
1 2 3
int a , b ;
char InputFormat ;
cin >> a >> InputFormat >> b ;
BUT you know, it doesn't work in all situations, I mean I need something which I have more control on.
Thank you all in Advaanced
Well, the scanf version doesn't work in all situations either.
If you need more precise control, you'd need to explicitly test for the actual '.' character. You might also want to stop ignoring whitespace (default is to ignore whitespace) after getting the first int.