Help with File I/O

This is a discussion on Help with File I/O within the C++ Programming forums, part of the General Programming Boards category; I'm making a program to play the Craps game. Whenever it rolls, I want to put the total of the ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    117

    Help with File I/O

    I'm making a program to play the Craps game. Whenever it rolls, I want to put the total of the dice in a separate file. This is the code for the first roll and writing to the file

    Code:
    while(round <= 10) {
                     roundWin = false;
                     roundOver = false;
                     roll();
                     if(argc != 2) {
                             cout<<"Usage "<<argv[0]<<endl;
                     }
                     else {
                        ofstream otherFile ("totals.txt");
                        if(!otherFile.isOpen()) 
                             cout<<"Could not open file!"<<endl;
                        else {
                             otherFile<<total<<endl;     
                        }
                        otherFile.close();
                        }
                     }
    It tells me that
    line 33 (which is ofstream otherFile ("totals.txt") "'variable std:fstream otherFile'" has initializer but incomplete type.

    I'm not sure what this means. I make a new ofstream and give it the file "totals.txt". What else is needed?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    You need to #include <fstream> to use file streams.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-31-2004, 12:21 AM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 09:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21