A question about output.


 
Thread Tools Search this Thread
Top Forums Programming A question about output.
# 1  
Old 04-14-2003
A question about output.

I am learning output the data to a file using "ofstream". I need to read data from a file and output the result to the other file in 2 different ways. To do that I have to provoke two functions, and they have to output the result to the same text file. My problem is: they are correct on the screen (output first function and then the second), but when they output to the text file, the second one always erras or cover the first one.

I think it might because after the first function finished, the second function open the file again and output from the beginning. How can I make it begin from the end of first function's output?

Here is my code:

#include <iostream>

using namespace std;

void functionOne()
{
...
ofstream outfile("a.txt");

outfile << data << data ...;
}

void functionTwo()
{
...
ofstream outfile("a.txt");

outfile << data << data ...;
}

int main()
{
...
functionOne();
...
functionTwo();
...
return 0;
}
# 2  
Old 04-18-2003
Replace ofstream outfile("a.txt"); in the second function with ofstream outfile("a.txt", ios::app);.

The default when you just include the filename is ios::out which overwrites the file if it exists.
# 3  
Old 04-18-2003
Thanx, I got that already. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

INPUT/OUTPUT question

Hi All, Is it wrong to do something like this: ssh -T $PROXY_USER@$PROXY_SERVER < script.txt > ssh_output.log I ran and it works fine and does what I need. I wanted to pass a set of commands to the ssh session and store an output in the log file. Thanks (4 Replies)
Discussion started by: rdogadin
4 Replies

2. Shell Programming and Scripting

A Question Regarding Timers and Output

Hi there. I am fairly new to scripting in BASH so please forgive my clumsy syntax and analogy as I try to explain what I am trying to accomplish. I have a list of mundane functions that I currently call from a script file. What I wish to do is to accurately record into a log file the times that... (17 Replies)
Discussion started by: Tenuous
17 Replies

3. Shell Programming and Scripting

Command Output Question

Hi everyone-- I'm new to these forums and shell scripting, and I'm trying to write a script that checks if a particular ip is pingable My idea was to check if the output of the command ping <some ip> -c 1 -w 1 had the string: "1 packet transmitted, 1 received"How would I go about doing this?... (2 Replies)
Discussion started by: Prodiga1
2 Replies

4. Solaris

Question on kstat output

I'm having a little trouble understanding the output I'm seeing from kstat for the "net" class. I'm seeing a lot of entries with "mac" as the name, like this. module: bge instance: 3 name: mac class: net ... (3 Replies)
Discussion started by: Midcain
3 Replies

5. Shell Programming and Scripting

Output file question

I am running a shell script which executes a bteq script and the output of the BTEQ script is dumped in the standard output file. The output of the bteq execution is a table with 30 columns and the width of the output would be about 800 characters for each record. My current output only shows 3... (3 Replies)
Discussion started by: Mihirjani
3 Replies

6. UNIX for Dummies Questions & Answers

Question about formatting the output

I need to ask a question on how to format the output in a csv format. Right now i am running a shell script which executes a command and the following output is append through a unix script in a .csv file. So the output of xyz.csv is as follow :- 1. Number = 25 Amount $84,132.22 2.... (1 Reply)
Discussion started by: chris1234
1 Replies

7. Shell Programming and Scripting

Question about output to file

Hi, I am try to setup a FOR loop script to find out all the existing linux workstations in the network w/ ip address, hostname and linux version. I created a basic FOR loop script: for i in $(seq 1 254) do echo 10.72.169.$i >> result ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname"... (1 Reply)
Discussion started by: beeloo
1 Replies

8. UNIX for Dummies Questions & Answers

wget output question

Hello there, İ want to ask a very simple question. I want to read the output messages of wget both in terminal and also put them into a text file. i know that by using -o flag, i can log the messages into a text file but then i won't be able to see them on terminal. I'd appreciate any help... (1 Reply)
Discussion started by: sertansenturk
1 Replies

9. Shell Programming and Scripting

display and output...question

Hi, I have a small question about the value cannot display correctly: MSG=log fruit=apple print "No $fruit in the store" > "$MSG/fruit_message.txt" output: No $fruit in the store should be: No apple in the store AND $MSG/fruit_message.txt ----------> cannot find the... (5 Replies)
Discussion started by: happyv
5 Replies

10. UNIX for Dummies Questions & Answers

Question on prtdiag output ...

Hello all , This is the output of my prtdiag command ...The speed of each of the CPUs is listed below (1281 MHz ) ..That's fine ..I'm confused about the (System clock frequency: 183 MHZ ) ..What is the difference between System Clock freq and CPU freq ...THanks.. System Configuration: Sun... (5 Replies)
Discussion started by: luft
5 Replies
Login or Register to Ask a Question