Writing string to file

Hi all,

I am currently creating a banking application with many features. One of the features is that it has to output transactions to a file.

I am trying to figure out how to output variables and strings using the 1 write function.

Example, let's say my text file I am outputting to is called output.txt.

I could use:

output <<"test text" <<variable.getNumber() <<"will output an integer number";

...which is fine, but it overwrites the text in the file each time the function is called, so I want to use the write function, which apparently adds to the text file instead of overwriting.

The problem is, I cant figure out how to provide the write function with multiple strings/variables as it only lets you declare 2 arguments, char and streamlength (which will also be a problem doing it this way).

Any thoughts are much appreciated.

Thanks

Matt
Last edited on
You can use append mode:

1
2
ofstream outfile;
outfile.open ("output.txt", ios::out | ios::app);


and then continue as usual.
Working, thanks very much!
Topic archived. No new replies allowed.