473,320 Members | 1,839 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,320 software developers and data experts.

setiosflag under the flow of the program

I want to change the mode of access to
code
ofstream transfer;
\code

so that I can alternately overwrite or append to it. What kind (type) of variable should I use to hold "ios::app" or "ios::out" ?

This is the point at the program:


code
string label("2");
.....
some code that may chage label to "1";
..........
if (label == "1") {transfer << setiosflags(method);};
/code

and I should have method to be either of "ios::app", "ios::out" .

I have tried
code
string method;
/code
and then

code
setiosflags(method.c_str())
/code

withouth success. I know that ios::app is equivalent to 8 or is it equivalent to "8"?

Thanks for help
Tarcisio
May 31 '15 #1
1 1626
weaknessforcats
9,208 Expert Mod 8TB
setiosflags is a manipulator. You use it with the ofstream insertion operator:

os << setiosflags(std::ofstream::out | std::ofstream::app);

Mnaipulators are functions that take an ostream first argument, your own second argument and return and osteam&. This makes them useable with the ostream operator<<.

MyOfstream.open ("Myfile.txt", std::ofstream::out | std::ofstream::app);

The openmode is a bitfield si it's neither 8 nor "8". It's std::ofstream::app.

Since ofstream derives from ios_base, you can also use ios::out | ios::app.
Jun 1 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Albert Ahtenberg | last post by:
Hello, I had some bad experience with code organization and script functionality in writing my php based applications. And as the applications get bigger in scale it gets even worse. Therefore,...
7
by: jacob navia | last post by:
Suppose that you want to know where your program has passed, i.e. the exact flow of the program. A brute force solution is to make an array of n lines, n being the number of lines in the...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
1
by: Brett | last post by:
I'd like to have all of my documentation in one place. I use the following for documenting code: - attributes for certain types of documentation - use of the C# generated inline XML...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
6
by: Crooter | last post by:
Hello colleagues, Could anybody tell me if there are existing open-source solutions to extract the program tree using a program source code? I'm aware that GCC has program flow information and...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
1
by: tarcisio | last post by:
In a program I want to chang the behavior of ofstream so that I can either append or rewrite a file. What is the type of the flags ios::app, ios::out so I can use a variable to switch between under...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.