ifstream performance.

A

aTuL

Hi All,

I am trying to open a ~720 Megs of file and print it. the code looks
like this.

ifstream ratingFile(strFileName.c_str());

if(!ratingFile.is_open()){
cout<<"Error: input file for ratings could not be opened.
Quitting\n"<<endl;
exit(GENERIC_ERROR);
}

while(!ratingFile.eof()){
//string strRatingline;
char strRatingline[20000];
cin>>strRatingline;
cout<<strRatingline;
}

When I run the code it just hangs at cin statement for really long.
Now what that makes me think is is my code wrong or something or it is
just reading all of the data and then plans to fill in my string?
 
A

Atul.

Hi All,

I am trying to open a ~720 Megs of file and print it. the code looks
like this.

        ifstream ratingFile(strFileName.c_str());

        if(!ratingFile.is_open()){
            cout<<"Error: input file for ratings could not be opened.
Quitting\n"<<endl;
            exit(GENERIC_ERROR);
        }

        while(!ratingFile.eof()){
            //string strRatingline;
            char strRatingline[20000];
            cin>>strRatingline;
            cout<<strRatingline;
        }

When I run the code it just hangs at cin statement for really long.
Now what that makes me think is is my code wrong or something or it is
just reading all of the data and then plans to fill in my string?

ok I got it. my bad.
 
T

Thomas J. Gritzan

Atul. said:
Hi All,

I am trying to open a ~720 Megs of file and print it. the code looks
like this.

ifstream ratingFile(strFileName.c_str());

if(!ratingFile.is_open()){
cout<<"Error: input file for ratings could not be opened.
Quitting\n"<<endl;
exit(GENERIC_ERROR);
}

while(!ratingFile.eof()){
//string strRatingline;
char strRatingline[20000];
cin>>strRatingline;
cout<<strRatingline;
}

When I run the code it just hangs at cin statement for really long.
Now what that makes me think is is my code wrong or something or it is
just reading all of the data and then plans to fill in my string?

ok I got it. my bad.

There is still an issue with your use of eof() described here:
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top