I'm having trouble figuring out how to copy the data from the two txt files into a vector. I'm trying to do this so I can use vectors sort function for alphabetizing. With the way I've tried to write the code, I keep getting
77 request for member `SIZE1' in `insA', which is of non-class type `int[((unsigned int)((int)SIZE1))]'
Thanks
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#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 lineCountA = 0;
int lineCountB = 0;
string lineA;
string lineB;
//Retreive his family's grades.
hisFamily;
if(hisFamily.fail())
{
cerr << "ERROR: Cannot open " << theAdopted << ". \n";
return EXIT_FAILURE;
}
//Retreive her family's grades.
herFamily;
if(herFamily.fail())
{
cerr << "ERROR: Cannot open " << theOriginals << ". \n";
return EXIT_FAILURE;
}
//Call theBigPicture.
ourFamily;
if(ourFamily.fail())
{
cerr << "ERROR: Cannot open " << theBigPicture << ". \n";
return EXIT_FAILURE;
}
//Copy data hisFamily to ourFamily.
getline(hisFamily, lineA);
getline(herFamily, lineB);
while(lineA.length() != 0 && lineB.length() != 0)
{
lineCountA++;
lineCountB++;
ourFamily << lineA << endl;
ourFamily << lineB << endl;
getline(hisFamily,lineA);
getline(herFamily,lineB);
}
cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
//Close files.
hisFamily.close();
herFamily.close();
ourFamily.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.ignore(nextCh);
hisFamily.get (nextCh);
}
if(!hisFamily.eof())
{
ourFamily.put(NWLN);
charCount++;
}
return charCount;
}