Tough times detecting the "\n\n"

i really wasted so much time trying to figuer out a way whenever the user finish his input he do a double enter which is a new line


i tried scanf and cin

if(scanf("\n\n"))

and
string s
cin>> s;
if(s=="\n\n")//Do something


but it was too late till i figured that c++ does not read new lines is that true or there is actually a way to do so ?
if( std::getline(std::cin, s) and s.empty() )
thanks ^^
btw, to answer this part of the question
zeroblank wrote:
i figured that c++ does not read new lines is that true

not quite, C++ is only doing what you told it to do.

if(scanf("\n\n"))

To scanf, the newline character is a special instruction that tells scanf to enter a loop reading and discarding every space, tab, and newline until it finds something that isn't.

http://www.cplusplus.com/reference/cstdio/scanf or http://en.cppreference.com/w/cpp/io/c/fscanf both say that in almost the same words, see the paragraph beginning with "Whitespace character:" (cplusplus.com) or "whitespace characters:" (cppreference.com)

cin>> s;
The operator>> from stream to string first enters a similar loop, consuming and discarding all whitespace unless configured to do otherwise (with noskipws).

likewise, see
http://en.cppreference.com/w/cpp/string/basic_string/operator_ltltgtgt and http://www.cplusplus.com/reference/string/string/operator%3E%3E/ (I think cppreference is more detailed here, especially if you click on the FormattedInputFunction link)

Why do you expect something else from scanf and >>? Is there incorrect documentation floating somewhere?

Last edited on
Topic archived. No new replies allowed.