Help with file in c++

Hello,
How print of the file of end of file for start of file. Because this normal this start and go until the end, for example:

historico.txt:
Sum: 3 4 5 6 = 18
Sum: 2 3 4 5 = 32
Sum: 3 4 5 6 = 50
Sum: 1 2 3 4 = 60
Sum: 5 6 7 = 78
Sum: 3 3 5 6 = 17
Sum: 2 2 = 4

My code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    string operacao;
    ifstream input("historico.txt");

    while(!input.eof()){
        operacao = "";
        while(input >> operacao && input.peek() != '\n'){
            cout << operacao << " ";
        }
        cout << operacao << endl;
    }

    return 0;
}


But i want print so:

Sum: 2 2 = 4
Sum: 3 3 5 6 = 17
Sum: 5 6 7 = 78
Sum: 1 2 3 4 = 60
Sum: 3 4 5 6 = 50
Sum: 2 3 4 5 = 32
Sum: 3 4 5 6 = 18

How make print? Help me!!!

You need to say what you mean or there's no helping you.

Do you mean that you want the output have lines in the reverse order of the input?
Yes
You have to read the file in and store it in a container that can be sorted.
Then you need to sort the content of the container.
Then you print the content of the container.

The standard library has all the things you need.

Containers are here: http://en.cppreference.com/w/cpp/container
Find something suitable, we tend to use vector by default and choose something else when vector won't do.

The algorithms are here: http://en.cppreference.com/w/cpp/algorithm
Look for something that'll do the sort for you.
Topic archived. No new replies allowed.