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;
}