Thread: output file

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    Angry output file

    I am trying to work with outputting files from a program. I thought I knew the basics of how to output to an output file but I can't get it to work. I keep getting errors:

    cpp(34) : error C2872: 'ostream' : ambiguous symbol
    cpp(34) : error C2248: 'ostream:stream' : cannot access protected member declared in class 'ostream'
    c:\program files\microsoft visual studio\vc98\include\ostream.h(99) : see declaration of 'ostream:stream'
    cpp(35) : error C2039: 'open' : is not a member of 'ostream'
    c:\program files\microsoft visual studio\vc98\include\ostream.h(59) : see declaration of 'ostream'
    Error executing cl.exe.

    .obj - 3 error(s), 0 warning(s)

    any help is appreciated (This is only my 3rd C++ program so I am by no means an expert at this!)


    //************************************************** **********
    #include <ctype.h>
    #include <fstream.h>
    #include <ostream.h> //for file I/O
    #include <iostream.h>
    #include <iomanip>
    using namespace std;


    int main()
    {
    double num1;
    double num2;
    char math;
    char AGAIN='Y';
    ostream outData; // internal name to represent output file
    outData.open("results.dat");


    cout << "format is <number> <operation> <number>" << endl;
    cout << "operations are +, -, *, /" << endl;
    cin >> num1 >> math >> num2;


    while ((AGAIN =='Y') || (AGAIN =='y'))
    {

    switch(math)
    {
    default:
    cout << "Invalid operation." << endl;
    cout << "Press any key to exit" <<endl;
    break;

    case '+':
    cout << num1 + num2 << endl;
    break;

    case '-':
    cout << num1 - num2 << endl;
    cout << "Press any key to exit" <<endl;
    break;

    case '*':
    cout << num1 * num2 << endl;
    cout << "Press any key to exit" <<endl;
    break;

    case '/':
    cout << num1 / num2 << endl;
    cout << "Press any key to exit" <<endl;
    if (num2 == 0)
    {
    cout << "Can't divide by ZERO!" <<endl;
    }
    break;







    } //end of switch



    cout << "Do you want to continue? Y/N" <<endl;
    cin >> AGAIN;//value to continue or to exit the program


    if ((AGAIN == 'Y') || (AGAIN == 'y'))

    {
    cout << "format is <number> <operation> <number>" << endl;
    cout << "operations are +, -, *, /" << endl;
    cin >> num1 >> math >> num2;
    }//end of if

    }//end of while

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    >ostream outData
    should be 'ofstream outData'

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    3
    Thanks, I'll give it a try!

  4. #4
    Unregistered
    Guest
    I just noticed something in passing...unless I'm missing something, you don't need to include ostream.h and iostream.h, explicitly. You only need fstream.h. Making that ostream an ofstream, like clownpimp said, should work also.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    tried it

    I tried what you and clownPimp said by changing ofstream outData and now I'm getting the following error.

    cpp(34) : error C2872: 'ofstream' : ambiguous symbol
    Error executing cl.exe.

  6. #6
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    you are using fstream.h and ostream.h both for files. i suggest that you use only fstream
    -

  7. #7
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    fstream.h - ostream.h - istream.h

    take a look at the structure of these and
    notice how there all derived

    so including both rather than just fstream is redundent

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM