Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help on ofstream ?

Reply
Thread Tools

Help on ofstream ?

 
 
tvn007@hotmail.com
Guest
Posts: n/a
 
      11-09-2005
could someone please help me to point out what wrong with the code
below ?

#define OUPUT_DIR "/home/user/OUT/test.out"
if (appenndmode=="YES"){
ofstream out(OUTPUT_DIR,ios::app); //error: 'out' undeclared
}
//////////////////////////////////////////////////////////
However, it works if I do this:
#define OUPUT_DIR "/home/user/OUT/test.out"

ofstream out(OUTPUT_DIR,ios::app);

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-09-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> could someone please help me to point out what wrong with the code
> below ?
>
> #define OUPUT_DIR "/home/user/OUT/test.out"
> if (appenndmode=="YES"){
> ofstream out(OUTPUT_DIR,ios::app); //error: 'out' undeclared
> }
> //////////////////////////////////////////////////////////
> However, it works if I do this:
> #define OUPUT_DIR "/home/user/OUT/test.out"
>
> ofstream out(OUTPUT_DIR,ios::app);
>


If you put a variable declaration inside an if statement then it only
exists inside that if statement. So when you try to use it outside the
if statement you get an undeclared error.

You probably want something like this

ofstream out;
if (appenndmode=="YES"){
out.open(OUTPUT_DIR,ios::app);
}

john
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ofstream help needed ern C Programming 3 02-02-2006 09:16 PM
ofstream * vs. ofstream Squid Seven C++ 5 07-14-2005 07:34 AM
Help: ofstream issues fasteddie203@gmail.com C++ 0 06-29-2005 10:52 PM
seemingly simple ofstream problem please help Tom Johnson C++ 4 08-15-2003 10:49 PM
help: ofstream doesn't always create files? james545@my-deja.com C++ 0 07-16-2003 02:27 PM



Advertisments