The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Question about output to file beeloo Shell Programming and Scripting 1 04-25-2008 03:20 PM
wget output question sertansenturk UNIX for Dummies Questions & Answers 1 04-19-2008 12:01 PM
display and output...question happyv Shell Programming and Scripting 5 01-25-2007 02:14 AM
Question on prtdiag output ... luft UNIX for Dummies Questions & Answers 5 11-14-2006 12:27 PM
Further question on 'ifconfig' output mint1981 UNIX for Dummies Questions & Answers 1 09-10-2002 11:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-14-2003
HOUSCOUS HOUSCOUS is offline
Registered User
  
 

Join Date: Feb 2002
Location: Houston TX
Posts: 123
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 (permalink)  
Old 04-18-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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 (permalink)  
Old 04-18-2003
HOUSCOUS HOUSCOUS is offline
Registered User
  
 

Join Date: Feb 2002
Location: Houston TX
Posts: 123
Thanx, I got that already.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0