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