-
Help with program
ok i am in the beginning stages and right now im just trying to make sure that my program opens a file for reading and opens a file for me to write output to but for some reason im gettin 26 errors using msv C++. Can someone help?
Code:
#include <stdlib.h>
#include <iostream>
#include <iomanip.h>
#include <fstream>
using std ::cout;
using std ::cin;
using std ::cerr;
using std ::ios;
using std ::endl;
using std ::ifstream;
int main()
{
//ifstream constructor opens file
ifstream inputFile("input.dat", ios:: in);
//exit program if unable to create file
if( !inputFile)
{
cerr<<File could not be opened"<<endl;
exit(1);
} //end if
//ofstream constructor opens file
ofstream outputFile("output.dat", ios:: out);
//exit program if unable to create file
if( !outputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
return 0;
}
-
- cerr<<File could not be opened"<<endl;
There's a missing " in this line.
-
Still giving me 6 errors
Code:
#include <stdlib.h>
#include <iostream>
#include <iomanip.h>
#include <fstream>
int main()
{
//ifstream constructor opens file
ifstream inputFile("input.dat", ios::in);
//exit program if unable to create file
if( !inputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
//ofstream constructor opens file
ofstream outputFile("output.dat", ios:: out);
//exit program if unable to create file
if( !outputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
return 0;
}
-
Actually just 1:
Should be #include <fstream.h>
-
i keep gettin this error, please tell me the problem
Code:
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
int main()
{
//ifstream constructor opens file
ifstream inputFile("input.dat", ios::in);
//exit program if unable to create file
if( !inputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
//ofstream constructor opens file
ofstream outputFile("output.dat", ios:: out);
//exit program if unable to create file
if( !outputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
return 0;
}
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0x66C has exited with code 0 (0x0).
The program 'C:\Documents and Settings\Master\Debug\test.exe' has exited with code 0 (0x0).
-
you're running it in the debugger or something... but those aren't errors. It's just that the prog runs and quits before you notice. The dll thing happens when you start the prog in the debugger, and when it quits, it says that the app exited with code 0.
-
-
try putting the line:
cin.get();
just before the the line:
return 0;
that should hold open so you can see the output until you push a key. As for the degugger thingy, I suspect there is a flag or a toggle or something to change. If you indicate what compiler you're using, somebody can probably tell what it is.
-
-
im trying to read data from a file in so i can do some things with it. the file looks like this:
Ray L. Jones 3942
Alice K. Brown 8300
Gill R. Alante 4301
So far the code i have looks like this :
Code:
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
void print(
int main()
{
//ifstream constructor opens file
ifstream inputFile("input.dat", ios::in);
//exit program if unable to create file
if( !inputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
//ofstream constructor opens file
ofstream outputFile("output.dat", ios:: out);
//exit program if unable to create file
if( !outputFile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
} //end if
char fName[10];
char mInitial[2];
char lName[10];
int empID;
//read data from input file
while(inputFile>>fName>>mInitial>>lName>>empID)
{
}
return 0;
}
-
Post the exact error message.
Is what you posted before the _entire_ error log?
-
i fixed that problem now im trying to read in data like it says on my post above.