mercredi 21 janvier 2015

while cin.get leading to an infinite loop when loading from file

I have the following code (this just part of a bigger application but the issue seems to be coming from the following):



char inputChar;
while (cin.get(inputChar)){
cout<< inputChar<< "\n";
}


when providing the application with its input from the console, such as: 'echo "aaaaa aaaaa"|tst' (where the program above has been compiled to tst.out) the program works correctly, however when I provide the input via a text file (ie './tst mytest.txt') it seems to run into an infinite loop (the cursor just moves to the next line and remains there, never getting the prompt again) no matter the contents of the file itself.


Does anyone have any idea as to why this is happening, and what i can do to fix this behavior.


ps: I am compiling and running this on a unix terminal.


Thanks


Aucun commentaire:

Enregistrer un commentaire