What am I doing wrong I am not getting these values from the input file to even display correctly or sort in order. Give me some direction?

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>

using namespace std;
class CommandLineException
{	
	public:
	CommandLineException(int max, int actual)
	{	
		cout << " Too many command line arguments. " << endl;
	}
};


class FileException
{
	public:
	FileException(char* fn)
	{
		cout << " File " << fn << " could not be opened. " << endl;
	}
};
class Sort 
{
	public:
		Sort();
		void read_list(ifstream& i );
		void selection_sort();
		void swap(int& x, int& y);
		void display(ofstream& o);

	private:
		
		vector<int> list;
};  

Sort::Sort()
{
	vector<int> list(1);
}

void Sort::read_list(ifstream& i)
{
	int num = 0;
	while(true)
	{
		i >> num;
		
		if( i.eof())
		{
			break;
		}
		list.push_back(num);
	}
}		

void Sort::selection_sort()
{
	int size = list.size();
	int min=0;
	int temp = 0;
	int i = 0;
	for( temp = 0; temp < size -1; temp++)
	{
		min = temp;
		
			for( i = temp + 1; i < size; i++)
			
				if ( i < min) 
					min = i;
				
			swap(temp,min);
	}
}

void Sort::swap(int& x, int& y)
{
	int temp = 0;
	temp = x;
	x = y;
	y = temp;
}

void Sort::display(ofstream &o)
{
	
	
	o << endl;
	o << "Unsorted list:  " ;
	o << endl;
	o << " Sorted list:" ;
	
}
	

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;
		o << num1.read_list(i);

		
		

		
		
		
       	o.close();
		i.close();
	} catch(...)
		{
		cout <<  " Program Terminated. " << endl;
		exit(EXIT_FAILURE);
		}
	

	
	return 0;
}
o << num1.read_list(i);

function read_list() returns void, so the above line will not compile.

Yeah, that was one of the errors. that command may work on linux but not visual C. Also, had a problem with my sort function. so it works now. thanks for the inputs everyone.

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.