Thread: Help with File I/O

  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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM