Putting strings into a file

I have an assignment for my programming class where I need to take an existing text file, extract each line individually, sort them in alphabetical order, and then put all the lines into a new text file in alphabetical order. The two parts I am having trouble with are taking each line out of the file (there are thousands of lines) and putting them into a vector of strings. If I could get the vector with all the lines in it, I know how to sort it alphabetically, but once that is done, I don't know how to write the new sorted lines into a new text file. Any help would be appreciated. The file is an Apache web log taken from a web server.
1
2
3
4
5
6
7
8
9
std::vector<std::string> lines;

{
    std::string line;
    while(std::getline(MyInputFile, line))
    {
        lines.push_back(line);
    }
}
After sorting:
1
2
3
4
for(std::size_t i = 0; i < lines.size(); ++i)
{
    MyOutputFile << lines[i] << std::endl;
}
Awesome. Thanks.
One more thing: what is std::size_t ? and can it be replaced with just an int ?
It can not be replaced with just "int" because "int" is signed and size_t is unsigned - but you can use "unsigned int". The problem is that on some compilers and operating systems, size_t might not be an unsigned int, so to be sure you use size_t always and not just plain unsigned int.
Topic archived. No new replies allowed.