I'm attempting a little self learning while on spring break I've created a program that will accept words store them in a file then print them out to the console. I am looking for the best way to print them in alphabetical order instead of the order they were inputted. I have seen a few examples online of how to do this with a vector but we haven't really touched on that in class yet so I'm wondering if there is a way to do it without using vectors?
This is what I have so far that takes input stores it in the file until "quit" is entered then it will print the words back to the console I'm using the using namespace std; for simplicity's sake I know most view it as bad practice. thanks for any help.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
string input;
ofstream file;
file.open("words.txt");
while(input != "quit"){
cin >> input;
file << input << std::endl;
if(input == "quit"){
file.close();
}
}
fstream dataFile("words.txt", ios::in);
if(dataFile.fail())
{
cout << "Error opening File..." << endl;
return 0;
}
while(dataFile >> input)
{
cout << input << std::endl;
}
dataFile.close();
return 0;
}