User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,001 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,177 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 4652 | Replies: 3
Reply
Join Date: Jun 2005
Location: California
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Help C++ vector question?

  #1  
Oct 11th, 2005
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]  << " " ;

}

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,561
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 860
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ vector question?

  #2  
Oct 11th, 2005
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.
Reply With Quote  
Join Date: Jun 2005
Location: California
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Help Re: C++ vector question?

  #3  
Oct 11th, 2005
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++?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,561
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 860
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ vector question?

  #4  
Oct 11th, 2005
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC