| | |
Ignoring First Line of File I/O
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi.. How do I skip the first line of a text file. I am not using getline() so I think I cannot use ignore() function. Is there any other way to ignore first line ?
Thanks
C++ Syntax (Toggle Plain Text)
................. FILE *in; char line[1000]; char *token; in = fopen(argv[1],"rt+"); if( in == NULL) exit(1); int i=0; while(! feof(in)) { //in.ignore(1000, '\n'); // std::in.ignore ( 1000, '\n' ); fgets(line, 1000, in); .................................
Thanks
0
#3 Oct 19th, 2009
You could try this:
Hope this helped!
Edit: I mean the same thing as what Ancient Dragon said in his post... He answered as I was typing this...
C++ Syntax (Toggle Plain Text)
FILE *in; char line[1000]; char *token; in = fopen(argv[1],"rt+"); if ( in == NULL) exit(1); int i=0; // Read the first line... move the file pointer to // point to the end of the first line. Note that the // definition for end-of-line is the '\n' character. fgets(line, 1000, in); while (! feof(in)) { // in.ignore(1000, '\n'); // std::in.ignore ( 1000, '\n' ); fgets(line, 1000, in); cerr << line << endl; }
Hope this helped!
Edit: I mean the same thing as what Ancient Dragon said in his post... He answered as I was typing this...
Last edited by amrith92; Oct 19th, 2009 at 3:06 pm.
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
0
#4 Oct 19th, 2009
•
•
•
•
You could try this:
fgets(line, 1000, in); while (! feof(in)) { // ... }
[edit]I think the
"rt+" mode is a nonstandard extension meaning "r+" .[edit]And it might be preferable to do
fgets(line, sizeof line, in);fgets(line, 1000, in);
) Last edited by Dave Sinkula; Oct 19th, 2009 at 3:43 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Concatenate string to each line in a file based on #chars in each line (Shell Scripting)
- comparing and inserting common line in other file (Shell Scripting)
- How to output random line from a file (Java)
- Reading line from a file and then replacing it (Assembly)
- Deleting a line from a file (PHP)
- how can i edit/change a line in a file? (Shell Scripting)
- read each line of file (C)
- Reading specific line in a file. / Searching (C++)
Other Threads in the C++ Forum
- Previous Thread: Visual C++ 2005 Express Problem to Locate and Download
- Next Thread: String input problem
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






