0
Cin.ignore
Why does cin.ignore(5); cause me to press the enter key five times when reading from a .txt file instead of skipping the first 5 characters of that file??? The fileâs first line says AMZN~Amazon.com So I put String amzn; Getline(infile,amzn); cin.ignore(5); cout << amzn << endl; But the whole line still shows up
1 Answer
+ 1
its normal because you make two errors:
1) calling getline you put the first line in amzn (then without discarding chars)
2) You call ignore on cin and cin is associated to console input (for this it want that you press some key 5 times)
You can try with
infile.ignore(5);
getline(infile, amzn);