•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,623 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 2,456 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: 4674 | Replies: 3
![]() |
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] << " " ;
}•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,641
Reputation:
Rep Power: 36
Solved Threads: 867
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Help with vector.. simple question (C++)
- C++ Help! (C++)
- Vector question (C)
Other Threads in the C++ Forum
- Previous Thread: Finding the object in an ArrayList
- Next Thread: private inheritance



Linear Mode