Okay I have a problem where the name of my vector is highlighted in yellow throughout my code and my output. I changed the name of the vector but on the output the word list is still highlighted in yellow, why? Below is my code:
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
using namespace std;
using std::vector;
#include "List01.h"
int main(int argc, char * argv[])
{
try
{
char infile[100]; // input file
char outfile[100]; // output file
if (argc == 1)
{
cout << " Enter the input file name. " << endl;
cin >> infile;
cout << " Enter the output file name. " << endl;
cin >> outfile;
cout << endl;
}
else if (argc == 2)
{
strcpy(infile, argv[1]);
cout << " Enter the output file name. " << endl;
cin >> outfile;
cout << endl;
}
else if ( argc == 3)
{
strcpy(infile, argv[1]);
strcpy(outfile, argv[2]);
}
else
{
throw CommandLineException(2,argc -1);
}
ifstream i(infile);
if(!i)
throw FileException(infile);
ofstream o(outfile);
if(!o)
throw FileException(outfile);
Sort num1;
num1.read_list(i);
o << "Unsorted list: "<< endl;
num1.display(o);
num1.selection_sort();
o << endl;
o << "Sorted list: "<< endl;
num1.display(o);
o.close();
i.close();
} catch(...)
{
cout << " Program Terminated. " << endl;
exit(EXIT_FAILURE);
}
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <cstdlib>
//____________________________________________________________________________________
using namespace std;
using std::vector;
#include "List01.h"
CommandLineException::CommandLineException(int max, int actual)
{
cout << " Too many command line arguments. " << endl;
}
//____________________________________________________________________________________
FileException::FileException(char* fn)
{
cout << " File " << fn << " could not be opened. " << endl;
}
//____________________________________________________________________________________
//____________________________________________________________________________________
//____________________________________________________________________________________
Sort::Sort()
{
vector< int > v1( 22 );
}
//____________________________________________________________________________________
void Sort::read_list(ifstream& i)
{
int num;
while(true)
{
i >> num;
v1.push_back(num);
if( i.eof())
{
break;
}
}
}
//____________________________________________________________________________________
int Sort::min_position(int to, int from)
{
int min_pos = from;
for ( int i = from + 1; i <= to; i++)
if ( v1[i] < v1[min_pos] )
min_pos = i;
return min_pos;
}
//____________________________________________________________________________________
void Sort::selection_sort()
{
int next;
for ( next = 0; next < v1.size() -1; next++)
{
int min_pos = min_position(v1.size() - 1, next);
if ( min_pos != next)
swap (v1[min_pos],v1[next]);
}
}
//____________________________________________________________________________________
void Sort::swap(int& x, int& y)
{
int temp =0;
temp = x;
x = y;
y = temp;
}
//____________________________________________________________________________________
void Sort::display(ofstream& o)
{
for( int a = 0; a < v1.size() - 1; a++)
o << setw(5) << v1[a] << " " ;
}