txt.file output in alphabetical order

Hello C++ friends,

trying to write a program to have a user input a number 1- 25 and display txt.file of names in alphabetical order to an exe.file. lost on the alphabet portion. I still trying to understand <vector>, but any help would be great.

The code I have so far is below.

Thanks,


ifstream inputfile;
int number;
string name;


// open file
inputfile.open ("lineUp.txt");


// get the filename from user
cout << " enter number to get names" << endl;
cin >> number;

if (number <= 0 ){
cout << " Error: Too many numbers try again" << endl;
cin >> number;}

if (number >= 26 ){
cout << " Error: Too many numbers try again" << endl;
cin >> number;}

if (inputfile.is_open())
{
cout << "File opened\n" << endl;
}
else
{
cout << ("File Failed to open") << endl;
return 0;
}

while (inputfile >> name)
{

cout << number << "\t" << name << endl;
}

//sort(name.begin(), name.end())


inputfile.close();.
[/code]
Last edited on
Topic archived. No new replies allowed.