RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Writing stuff inside files in C++ bloodshed

Join Date: Aug 2007
Location: South Dakota
Posts: 1,124
Reputation: vmanes is just really nice vmanes is just really nice vmanes is just really nice vmanes is just really nice 
Rep Power: 7
Solved Threads: 115
vmanes's Avatar
vmanes vmanes is offline Offline
Veteran Poster

Re: Writing stuff inside files in C++ bloodshed

  #2  
Nov 20th, 2007
You're trying to swim against the (file)stream.
  ifstream income;
  income.open ("Income.txt", ios::in);
  
  ifstream fixed_expenses;
  fixed_expenses.open ("Fixed Expenses.txt", ios::in);
  
  ifstream variable_expenses;
  variable_expenses.open ("Variable Expenses.txt", ios::in);
You are opening file handles of type ifstream, which are by default input handles. So, you don't need the "ios::in" mode parameters.

But, you seem to be trying to use them as output (writing) file handles. Perhaps what you really meant to do this in your declarations is:
  ofstream income;
  income.open ("Income.txt" );
  
  ofstream fixed_expenses;
  fixed_expenses.open ("Fixed Expenses.txt" );
  
  ostream variable_expenses;
  variable_expenses.open ("Variable Expenses.txt" );

//  then later in the code

       income << "Paycheck: " << paycheck <<  endl;
       //etc.
ofstream handles are, by default, output handles, so "ios::out" is not necessary.

Val
I am in mourning for my country.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:44 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC