473,401 Members | 2,146 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,401 software developers and data experts.

open a stream for app and out

Hi
I have a class with a private attribute std::fstream* fs_status;
in the ctor, I have
fs_status.open( f_name.c_str(), std::string::ios out | std::string::ios::app |
std::string::ios::out );
I basically need to create it if it is not there and
to open it for append AND for reading if it is there.

I am doing it right?

thanks
Feb 28 '07 #1
2 2465
Gary Wessle wrote:
Hi
I have a class with a private attribute std::fstream* fs_status;
in the ctor, I have
fs_status.open( f_name.c_str(), std::string::ios out | std::string::ios::app |
std::string::ios::out );
I basically need to create it if it is not there and
to open it for append AND for reading if it is there.

I am doing it right?
No.
First, fs_status should not be a pointer.
Second, if fs_status is a pointer, then your syntax is correct.
Third, what are all those std::string::'s doing in there?
Fourth, initalize fs_status in your class's initialization list, i.e.

my_class::my_class( const std::string& f_name )
: fs_status( f_name.c_str(), std::ios::out | std::ios::in |
std::ios::app )
{
// constructor body.
}

Note: I may have an incorrect set of flags (Josuttis table 13.33
indicates I might).

It looks like that in/out/append is not possible as a generic parameter,
it can either be in/out/trunc or out/app if it doesn't exist, but
in/out/app doesn't seem to be valid.

DISCLAIMER: I haven't played with iostream modes in a long time.
Someone with better knowledge than me should correct it.
Feb 28 '07 #2
Gary Wessle <ph****@yahoo.comwrites:
Hi
I have a class with a private attribute std::fstream* fs_status;
in the ctor, I have
fs_status.open( f_name.c_str(), std::string::ios out | std::string::ios::app |
std::string::ios::out );
and then
copy( lines.begin(), lines.end(), std::ostream_iterator<std::string>(iofs, std::endl) );
Feb 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marco Nicosia | last post by:
Hello gang, My coworker and I are writing a Python class for the other developers within our team. This class is supposed to encapsulate several things, including daemonizing, setting up...
4
by: Klaus Füller | last post by:
I would like to use the unix,et.al-fstat() system-call on some sort of stream which is already open and connected to a disk file. An example: I have an open stream and want to know the numerical...
9
by: Charles F McDevitt | last post by:
I'm trying to upgrade some old code that used old iostreams. At one place in the code, I have a path/filename in a wchar_t string (unicode utf-16). I need to open an ifstream to that file. ...
4
by: Simon Cheng | last post by:
Hi, How do I open a Word or Excel document inside an event handler (e.g., Page_Load())? Thanks, Simon
6
by: Shimon Sim | last post by:
Hi 1) Is it possible to force browser to open image in default windows application? That is what specifies in Folder Options for jpg extension. 2) Also if the 1) is possible is it possible to...
10
by: Gunnar G | last post by:
I'm having problem reading from the beginning of a file. Here is the code (more or less) ifstream codefin; ofstream codefout; while (not_annoyed)
0
by: Madhavi | last post by:
Hi I am working on a proted project from VB to C# in VB stream.open without any parameters works but in C# i need to pass certain arguments like Stream.Open(null,...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
16
by: Gary Wessle | last post by:
Hi please help with this. std::fstream iofs( f.c_str(), std::ios::in|std::ios::out ); std::cout << f << '\n' << iofs.is_open() << std::endl; puts out...
6
by: Andy2500 | last post by:
Hi, I'd like to upload an image to a folder, then I have 3 diffrents examples but all of them give an error "failed to open stream: Permission denied", althrough the C:\Inetpub\wwwroot is not...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.