Talk About Network

Google





Programming > C - C++ Learning > About ifstream
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 4203 of 4400
Post > Topic >>

About ifstream

by Joe <liuj0025@[EMAIL PROTECTED] > Jul 15, 2008 at 04:12 AM

Hello all,
I dont know how to fix it. The program is to open a file
"the_obtained_output", then open another file "verification1". The
first file can be opened successfully but I got a error message
"error: unable to open the input file: 000000".

I checked the codes, I found if I removed
       "for(float i;infile>>i;)
		prediction.push_back(i);
	for(vector<float>::size_type ix=0;ix!=10;ix++)
		cout<<prediction[ix]<<endl;",
the error message did not display.

Can anybody tell me why? I really dont know the reason.

The codes are listed below,

int main(){
	vector<float> prediction, observation;
	ifstream infile("the_obtained_output");
	if (!infile){
		cerr<<"error: unable to open the input file: "<<infile<<endl;
		return -1;
	}

	for(float i;infile>>i;)
		prediction.push_back(i);
	for(vector<float>::size_type ix=0;ix!=10;ix++)
		cout<<prediction[ix]<<endl;

	infile.close();
	infile.open("verification1");

	if (!infile){
		cerr<<"error: unable to open the input file: "<<infile<<endl;
		return -1;
	}
	return 0;
}


Thank you, all.
 




 3 Posts in Topic:
About ifstream
Joe <liuj0025@[EMAIL P  2008-07-15 04:12:32 
Re: About ifstream
"Jim Langston"   2008-07-15 04:16:39 
Re: About ifstream
James Kanze <james.kan  2008-07-15 05:52:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Fri Jan 9 5:24:54 PST 2009.