473,545 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on ofstream ?

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
1 1607
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2499
by: james545 | last post by:
I am having a problem with ofstream creating files. Sometimes when I run the program, ofstream creates a new file for writing and writes to it. No problem. But sometimes it fails to create the files altogether. Why doesn't it create files consistently? (My disk isn't full, and the file didn't previously exist) Thanks for your help. ...
4
2899
by: Tom Johnson | last post by:
Hi all, I cant believe that Im stuck on such simple code, but I am so... Im trying to open a text file for writing but can never get the file to initially open. Heres what Im having trouble with. ----------------------------------------------- #include <iostream.h> #include <fstream.h> void main()
5
2823
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
0
1276
by: fasteddie203 | last post by:
Hi, I hope this is appropriate for standard C++ group, I apologize if it is not. I'm trying to print to LPT1 using ofstream which works fine as long as the printer is connected - it doesn't need to be powered on. However, if there is no printer at all, it seems the ofstream won't detect the failure or close gracefully - but when the...
5
1747
by: Jintty | last post by:
Hi, I'm trying to write a program that will read a txt file, copy it into another text file and display the number of words, lines and paragraphs. I was able to get the copying portion done, but i'm struggling with the counters. processBlank is supposed to increment the number of words whenever it hits a nonblank, so i figured using if its...
3
1630
by: ern | last post by:
Is there a good example of simple usage of ofstream ? Also, I need to create a FOLDER before I create a file to write to. Is this possible ? If so, how ?
4
1826
by: lsu420luv | last post by:
'i have been working on this assignment for like 45 hours. the file reads from Piano.data and outputs into report.out. I have everything working, except for the fact that it will not repeat until the end of file is read. It just reads one display. Also the totalScore for each player seems to come one tenth off every time i run the program....
11
1620
by: Kush | last post by:
Hello All, I am having problem writing some data to file and I do not understand my mistake / misconception. I am trying to write some simple text to file but the text is rather output to screen! Below is my entire code from my problem, but I just want to focus on the method "write_percentage_per_side_to_file(ofstream &os)". From my...
6
2850
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7946
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7791
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.