Switching from formatted to unformatted input in C++
问题 I have an input text file. The first line has two int numbers a and b , and the second line is a string. I want to use formatted input to do file >> a >> b , and then unformatted input to get the characters of the string one by one. In between the two steps, I need to skip over the '\n' character at the end of the first line. I used while(file.get()<=' ' && !file.eof()); // skip all unprintable chars if(!file.eof()) file.unget(); // keep the eof sign once triggered to make the input format