Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
input whole line from file: c++
Name: moltar Date: September 29, 2003 at 21:49:40 Pacific OS: windows xp prof CPU/Ram: 700mhz 256 mb
Comment:
this is what total needs to be done http://www.cs.uakron.edu/~margush/210/Prog2.htm
what i can't figure out is how to input a whole line from a file into a character array. all my text shows is how to get a single word. i'm thinking it's cin.getline, but i'm not sure how the code would be written
Name: Ronin1 Date: September 30, 2003 at 10:55:07 Pacific
Reply:
As I recall, it *should* be something like
ifstream input; input.getline(..);
0
Response Number 2
Name: moltar Date: September 30, 2003 at 15:33:43 Pacific
Reply:
how's it all look together? i know this is wrong cause i only get a blank line =/
#include <iostream> #include <fstream> using std::ios;
int main(){ const int max = 14; char isbn[max]; std::ifstream input("somebook.dat",ios::in); input.getline(isbn,max,'\n'); std::cout << isbn << std::endl; return 0; }
0
Response Number 3
Name: moltar Date: September 30, 2003 at 17:24:29 Pacific
Reply:
okay, now i got it to input, but it doesn't see the eof and goes inf. -_-; stupid dat files
0
Response Number 4
Name: Ronin1 Date: September 30, 2003 at 23:03:16 Pacific
Reply:
I've been playing with C for months, so I've forgotten a lot of cpp. However, I *think* something like this will allow you to read the entire file. I haven't checked your program link, so I dunno what the program requires. :)
int ch;
while((ch = input.peek()) != EOF) { input.getline(isbn, max, '\n'); // do something with isbn }
input.close();
make sure you're not trying to read in more than your array can hold. Since you're using cpp, why not use the string class instead?
Summary: For completeness, I guess I'll throw in a Perl solution. srand; rand($.) < 1 && ($line = $_) while <>; print $line; Save the file as random.pl and execute it like so: C:\test>random.pl greetings...
Summary: hi all I have a bunch of txt files from which I need to extract different set of lines: from line 1 to line 3 to be stored in a single comprehensive file called “headings.txt” and from line 4 to ...
Summary: I am trying to delete blank lines from a text file when executing my batch file. I used the code found on this site @Echo off For /F "tokens=1 delims=" %%A in (c:\orig.txt) Do Echo %%A >> c:\new.tx...