473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1593
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
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...
4
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....
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
0
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...
5
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...
3
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
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...
11
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...
6
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.