// file.in
12
13
// main.cpp
fstream f("file.in", ios::in);
int n;
char c;
f >> n;
f.get(&c);
After extracting the number 12, what is the next character? Is it newline or ‘1’? If I call getline instread of get, do I get an empty line or ’13’?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It leaves the delimiter in the input buffer, so the next character you read will be a new-line. Note, however, that most extractors will skip white space (which includes
new-line) before anything they extract, so unless you do call something likegetlinethis won’t usually be visible.Edit: to test on something like ideone, consider using a
stringstream:I wouldn’t expect to see a difference between a
stringstreamand anfstreamin something like this.