I'm running DEV and am having trouble with my program finding the .txt files I'm trying to open.
I've had a hard time finding any curriculum on where to store files that need to be called by a program.
Right now, I have the program, both input files, and single output file all in the same folder.
The program will not open any of the files.
Is that an issue with the location of the files, or with the program itself??
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
#define theAdopted "The Adopted.txt" //His family
#define theOriginals "The Originals.txt" //Her family
#define theBigPicture "The Big Picture.txt" //Our family
//Function Prototypes
class KeepRunning { //Prototype needed to keep console from closing.
public:
~KeepRunning() {
cin.get();}};
//Copies text
int copyLine(ifstream&, ifstream&, ofstream&);
int main()
{
KeepRunning kr;
ifstream hisFamily("The Adopted.txt");
ifstream herFamily("The Originals.txt");
ofstream ourFamily("The Big Picture.txt");
int SIZE1 = 200, SIZE2 = 200;
int insA[SIZE1];
int insB[SIZE2];
int outs[SIZE1 + SIZE2];
int lineCount;
int index1 = 0;
int index2 = 0;
int A = 0;
int B = 0;
//Retreive his family's grades.
hisFamily.open(theAdopted);
if(hisFamily.fail())
{
cerr << "ERROR: Cannot open " << theAdopted << ". \n";
return EXIT_FAILURE;
}
//Retreive her family's grades.
herFamily.open(theOriginals);
if(herFamily.fail())
{
cerr << "ERROR: Cannot open " << theOriginals << ". \n";
return EXIT_FAILURE;
}
//Call theBigPicture.
ourFamily.open(theBigPicture);
if(ourFamily.fail())
{
cerr << "ERROR: Cannot open " << theBigPicture << ". \n";
return EXIT_FAILURE;
}
//Copy data hisFamily to ourFamily.
string line;
lineCount = 0;
getline(hisFamily, line);
while(line.length() != 0)
{
lineCount++;
ourFamily << line << endl;
getline(hisFamily,line);
cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
//Close files.
hisFamily.close();
herFamily.close();
return 0;
}
int copyLine
(ifstream& hisFamily,
ifstream& herFamily,
ofstream& ourFamily);
{
const char NWLN = '\n';
char nextCh;
int charCount = 0;
//Merge
hisFamily.get(nextCh);
while ((nextCh != NWLN) && !hisFamily.eof())
{
ourFamily.put(nextCh);
charCount++;
hisFamily.get (nextCh);
}
if(!hisFamily.eof())
{
ourFamily.put(NWLN);
charCount++;
}
return charCount;
}
}