Instream not working for file inputs (C++)
Fission and I had quite a long talk about this and we couldn't figure out why the code was not working. It builds with no errors but when I run it I get this. I continually built it after suggested changes, but each time it was just blank when I ran it.
The catch here is to read each line from the input.txt file and then print it out. Here's the data from the input.txt file: Following spoiler shows the code that should have printed out the contents above, but I got nothing. Of course later on I want to read the characters after the : symbol which I assume can be done by changing the while loop to while (getline(in, data, ':')) But right now nothing is getting stored into the data string variable. |
Re: Instream not working for file inputs (C++)
I looked into errors with it online and maybe this would be helpful:
Code:
3. Lastly, and perhaps more tricky. After reading the employee id using fin>>id; there will be a newline character remaining in the input buffer. |
Re: Instream not working for file inputs (C++)
I took your code.
The only thing I found wrong with it, was that the input.txt had to be in the correct folder, depending on how you launch it. If you're using cmdline, it should be right next to the executable. If you're using visual studio, it should be in the project directory. Your code works as intended. Tip: bool isopen = in.is_open(); |
Re: Instream not working for file inputs (C++)
Alright, now there's another problem. Pastebin of the code: http://pastebin.com/YPB4Sgq7
Since the text file is structured as follows: - Name\n - 4 quiz grades\n - Newline Gap to the next name There is a call to getline for the name first, then the for loop calls getline four times again for the quizzes, then getline is called after the loop to make up for that newline gap. But I'm getting garbage for output. Edit: Ok so adding endl to the end of the cout statements made the difference between Code:
C:\computing3\streamtest\streamtest\dist\Debug\Cygwin-Windows>streamtest.exe Code:
C:\computing3\streamtest\streamtest\dist\Debug\Cygwin-Windows>streamtest.exe |
All times are GMT -5. The time now is 11:03 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution