c++ text file redirection getline infinite loop -


so i'm having issue reading in text file using cin. here basic idea of code:

while(getline(cin,line) { cout << line << endl; } //do task return 0; 

the problem i'm running loop not terminate , //do task never run. solution i've found directly @ text file, see how many lines of text there are, , hard code conditional break out of it. have text file 5 lines , variable int row. this:

  while(getline(cin,line) { cout << line << endl; if(row == 5) { break; } //do task return 0; 

i tried googling can't seem find answer anywhere. ideas? , libraries i'm allowed use iostream.

you can use rdbuf redirect cin output following link you. http://www.cplusplus.com/reference/ios/ios/rdbuf/


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -