writing problems

This is a discussion on writing problems within the C++ Programming forums, part of the General Programming Boards category; I decided not to call programs within a program just yet. However, my program finally gives me the 4 highest ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Florida, Dade County, Homestrad, 33031
    Posts
    40

    writing problems

    I decided not to call programs within a program just yet. However,
    my program finally gives me the 4 highest numbers (on the screen) using:

    Code:
    cout << indexoffirst << " = "<< first << endl << endl;
    cout << indexofsecond << " = " << second<< endl << endl;
    cout << indexofthird << " = " << third << endl << endl;
    cout << indexoffourth << " = " << fourth << endl <<endl;
    Now I'm trying to get the program to write this info in a file. I first created / opened the file for reading using:


    Code:
    ifstream c_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
    
        if (!c_file )
        {
        out << "Can't open input file" << " Highest_Frequencies.txt " << endl << endl;
        cin.get();
        exit(1);
        }

    I then opened the file for writing using:

    Code:
            
    ofstream c_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
    
        if (! c_file )
        {
        cout << "Can't open input file " << endl << endl;
        cin.get();
        exit(1);
    I then try to write into the file using:


    Code:
      c_file >> indexoffirst >> " = " >> first >> endl >> endl;
        c_file >> indexofsecond >> " = " >> second >> endl >> endl;
        c_file >> indexofthird >> " = " >> third >> endl >> endl;
        c_file >> indexoffourth >> " = " >> fourth >> endl >> endl;

    but the writing is not happening... I get the following errors on build:


    Code:
    Error 1 error C2371: 'c_file' : redefinition; different basic types
    Error 3 error C2088: '>>' : illegal for class
    7 IntelliSense: no operator ">>" matches these operands

    The part that I'm having trouble with is code:
    Code:
      cout << indexoffirst << " = "<< first << endl << endl;
      cout << indexofsecond << " = " << second<< endl << endl;
      cout << indexofthird << " = " << third << endl << endl;
      cout << indexoffourth << " = " << fourth << endl <<endl;
    
            
            
            ifstream c_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
    
                if (!c_file )
                {
                cout << "Can't open input file" << " Highest_Frequencies.txt " << endl << endl;
                cin.get();
                exit(1);
                }
            
            
            
            ofstream c_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
    
                if (! c_file )
                {
                    cout << "Can't open input file " << endl << endl;
                    cin.get();
                    exit(1);
                }
    
    
            c_file >> indexoffirst >> " = " >> first >> endl >> endl;
            c_file >> indexofsecond >> " = " >> second >> endl >> endl;
            c_file >> indexofthird >> " = " >> third >> endl >> endl;
            c_file >> indexoffourth >> " = " >> fourth >> endl >> endl;

    Where am I wrong? . . . . therry

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    Error 1 error C2371: 'c_file' : redefinition; different basic types
    use different varable names for the input- and output-stream.

    BTW you cannot read into endl;
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some problems about writing connect 4
    By fail50 in forum C++ Programming
    Replies: 5
    Last Post: 04-04-2011, 09:43 AM
  2. Writing Code but am having problems
    By Choppers in forum C Programming
    Replies: 20
    Last Post: 06-25-2009, 07:18 PM
  3. Problems writing to a file
    By Dragoon_42 in forum C++ Programming
    Replies: 5
    Last Post: 02-09-2006, 11:44 AM
  4. Problems - writing File
    By MethodMan in forum C Programming
    Replies: 2
    Last Post: 03-30-2003, 12:36 PM

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