By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,905 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,905 IT Pros & Developers. It's quick & easy.

Help on ofstream ?

P: n/a
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);

Nov 9 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
tv****@hotmail.com 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
Nov 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.