alphabetical sort

I have a 18000 words document, each word on its own line. Can somebody show me a way to sort them in C++, please?
You could load the file into a sorted container (set<string> for example) and then print it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <set>
#include <string>
#include <algorithm>

int main()
{
    std::ifstream file("test.txt");

    std::set<std::string> data;
    for(std::string line; getline(file, line); )
        data.insert(line);

    for(const std::string& word : data)
        std::cout << word << '\n';
}
Topic archived. No new replies allowed.