PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed Need Money Easy and Quick?

Read file problem

 List
Subject: Read file problem
Poster: peter.vanna@gmail.com
Date: 23 Mar 2007 13:23:32 -0700
Related Postings: 1 2
I would like to write a program to read a text file (data.txt) on Windows and Linux machines.

data.txt is formated as follows:

1 10 100 1000 2 20 (a new but empty line)

My C++ program is:

*************************************** ifstream fp_input("data.txt"); int a,b;

while(!fp_input.eof()) { fp_input>>a;

cout<<"a="< while(fp_input.peek()!='\n' && fp_input.peek()!='\r' && ! fp_input.eof()) { fp_input>>b; cout< cout< However, the output of my program is:

1: 10 100 1000 2: 20 2:

I don't know why there is an extra "2" in the end of the output.

Could someone give me a clue to modify my program such that it can display "data.txt" properly under Windows and Linux?

Thanks.

 

Page2Go2.com is not responsible for content of this message.