There is no conversion. If the user enters a fraction (no double ), then extraction >> stops at the decimal point.
http://ideone.com/azdOrO
int main() { int x; std::cin >> x; std::cout << std::cin.rdbuf(); } input: 123.456 output: .456
If you want to mark the presence of a decimal point as an error, you will need to do something to extract it from cin and detect it.
One good parsing strategy with C ++ streams is getline , which you know you will handle in istringstream , name it s , and then make sure it is s.peek() == std::char_traits<char>::eof() when you're done. If you are not using getline to get the individual number, peek can check if the next character is a space (using std::isspace ) without consuming that character from the stream.
Probably the cleanest way to verify that input is complete, although it is somewhat esoteric, is to use std::istream::sentry .
if ( ! ( std::cin >> x ) || std::istream::sentry( std::cin ) ) { std::cerr << "Invalid or excessive input.\n"; }
This takes up space at the end of input. sentry also provides the noskipws option to avoid space usage.
if ( ! ( std::cin >> x ) || std::istream::sentry( std::cin, true ) ) { std::cerr << "Invalid or excessive input. (No space allowed at end!)\n"; }
Potatoswatter
source share