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]  << " " ;

}

Recommended Answers

All 3 Replies

I've read your question 3 times and the program once, but I still fail to understand the question. Yellow ? Where do you see the output colored in yellow? Must be your monitor doing that.

it is not the monitor. I am using linux environment. The output Sorted list and Unsorted list. The words list are colored yellow. However, when I capitilaze the word to Unsorted List and Sorted List, the output is correct. Is there something wrong with the format or is list a keyword in C++?

I see nothing in your code to cause that coloring behavior. list is not a keyword unless you include <list> c++ header file. Must be your os or the text editor you are using to display the output. c++ does not know anything at all about colors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.