three out of five file streams wont open, i believe its a problem with my ifstreams.
Posted
by user320950
on Stack Overflow
See other posts from Stack Overflow
or by user320950
Published on 2010-04-20T03:38:34Z
Indexed on
2010/04/20
3:43 UTC
Read the original article
Hit count: 318
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
ifstream in_stream; // reads itemlist.txt
ofstream out_stream1; // writes in items.txt
ifstream in_stream2; // reads pricelist.txt
ofstream out_stream3;// writes in plist.txt
ifstream in_stream4;// read recipt.txt
ofstream out_stream5;// write display.txt
int wrong=0;
in_stream.open("ITEMLIST.txt", ios::in); // list of avaliable items
if( in_stream.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here0, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n" << endl;
exit(1);
}
else{
cout << " System ran correctly " << endl;
out_stream1.open("ITEMLIST.txt", ios::out); // list of avaliable items
if(out_stream1.fail() )// check to see if itemlist.txt is open
{
wrong++;
cout << " the error occured here1, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n";
exit(1);
}
else{
cout << " System ran correctly " << endl;
}
in_stream2.open("PRICELIST.txt", ios::in);
if( in_stream2.fail() )
{
wrong++;
cout << " the error occured here2, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n";
exit (1);
}
else{
cout << " System ran correctly " << endl;
}
out_stream3.open("PRICELIST.txt", ios::out);
if(out_stream3.fail() )
{
wrong++;
cout << " the error occured here3, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n";
exit (1);
}
else{
cout << " System ran correctly " << endl;
}
in_stream4.open("display.txt", ios::in);
if( in_stream4.fail() )
{
wrong++;
cout << " the error occured here4, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n";
exit (1);
}
else{
cout << " System ran correctly " << endl;
}
out_stream5.open("display.txt", ios::out);
if( out_stream5.fail() )
{
wrong++;
cout << " the error occured here5, you have " << wrong++ << " errors" << endl;
cout << "Error opening the file\n";
exit (1);
}
else{
cout << " System ran correctly " << endl;
}
© Stack Overflow or respective owner