|
| ljrobison (57) | |||
| Well we're on I/O streams dealing with reading and writing to a data file in my C++ class and im completely lost. I just got over having swine flu and I'm pretty far behind. My book doesn't give any great examples on writing to a data file so I figured I'd ask here. The assignment is: <i>Write a C++ program that accepts lines of text from the keyboard and writes each line to a file name text.dat until an empty line is entered. An empty line is a line with no text that is created by pressing the Enter (or Return) key.</i> and heres my code so far:
But when I run it, it doesn't actually do anything is just exits right away. Any help would be appreciated. Thank you =) | |||
| Bazzy (4111) | |
Replace the if of lines 22-26 with a do-while and line 25 with getline(cin,line); | |
| ljrobison (57) | |
| Thanks so much, the input is working. But now it isn't writing it to the file. I should be able to figure this out though. | |
Last edited on | |
| Bazzy (4111) | |
| Hint: You need a file for output, not for input | |
| ljrobison (57) | |||
Ok, i changed it to this:
but it still isn't writing to file. | |||
Last edited on | |||
| Bazzy (4111) | |
| Where are you expecting it to write? Read carefully your code and you'll realise that you never tell to write anything on that file | |
| nemesiscplusplus (32) | |
| Yes, what you have done here is 1.) You open the file. 2.) You ask for the word. 3.) And you get that line. In here, there is no code that you says that you put it in your textfile. Read on I/O handling. Regards, Nemesis | |
This topic is archived - New replies not allowed.
