Talk About Network

Google





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

Re: About ifstream

by James Kanze <james.kanze@[EMAIL PROTECTED] > Jul 15, 2008 at 05:52 AM

On Jul 15, 1:16 pm, "Jim Langston" <tazmas...@[EMAIL PROTECTED]
> wrote:
> "Joe" <liuj0...@[EMAIL PROTECTED]
> wrote in message

> news:2e4dbb2c-f4ab-4fc2-9c65-e1b9d22b89fb@[EMAIL PROTECTED]
> > 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=3D0;ix!=3D10;ix++)
> > cout<<prediction[ix]<<endl;",
> > the error message did not display.

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

> Personally I don't reuse ifstreams myself.  I would just give
> the 2nd one a different variable name.

That's certainly the best solution.

In his case, the problem is simple: he only stops reading the
first file when an input fails.  And the failure flag is sticky;
all stream operations effectively become a no-op until it is
cleared.  An "infile.clear()" before the second open should do
the trick.

--
James Kanze (GABI Software)             email:james.kanze@[EMAIL PROTECTED]
 en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
 




 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:32:07 PST 2009.