Hello!!
I'm trying to write a file parser. I have just began and I stuck.
Let's assume that I have a file called 'profile.txt'. This file contains :
"
hello
"
2 new lines, the word "hello" and then 3 new lines (I opened the text file and pressed 2 times the enter key, then I wrote "hello" and then 3 times the enter key).
I wrote this program to count and confirm that the file contains 4 new lines. The line which contains the word hello, needs not to be counted.
So I wrote this :
Code:#include <iostream> #include <fstream> using namespace std; int main() { ifstream file("profile.txt"); string tmp; while(!file.eof()) { if(file.peek()=='\n') { cout<<"ignored"<<endl; file.ignore(1,'\n'); } getline(file,tmp,'\n'); } file.close(); return 0; }
This code however doesn't seems to be working. Any ideas where my code is wrong?
Thank you



LinkBack URL
About LinkBacks



