can anyone tell me why I am crashing when i run this ?
I am loading and then trying to combine 2 arrays to I can sort the final one:
thanks!
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::istream;
using std::ostream;
using std::ios;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <iomanip>
using std::left;
using std::right;
using std::setw;
void load (istream& infile, istream& infile2, ostream& outfile);
void main ()
{
ifstream infile("C:\\McD\\Cee_\\PROJECTS\\MyProjects_sem2\\HW_cpp\\HW7_4\\file1.txt");
if(!infile)
{
cerr << "Cannot open input file" << endl;
exit (1);
}
ifstream infile2("C:\\McD\\Cee_\\PROJECTS\\MyProjects_sem2\\HW_cpp\\HW7_4\\file2.txt");
if(!infile2)
{
cerr << "Cannot open input file" << endl;
exit (1);
}
ofstream outfile("7_4out.dat");
if(!outfile)
{
cerr << "Cannot open output file" << endl;
exit(1);
}
load(infile, infile2, outfile);
}
void load (istream& infile, istream& infile2, ostream& outfile)
{
int num[10];
int num2[10];
while (( infile ) && (infile2))
{
for (int i = 0; i <10; i++)
{
for (int j = 0; j < 10; j++)
{
infile >> num[i];
if(num[i] ==-1) return;
infile2 >> num2[j];
if(num2[j] ==-1) return;
//this is where i combine them..i think it's the problem?
((num[i+10])=(num2[j]));
cout << num[i] << endl;
cout << num2[j] << endl;
}//if
}//if
}//wh
}//fx