5 million is nothing to a modern computer.
a brute force hash and count would do this in a few seconds on a cheap laptop.
for reference, std::sort can sort 6 million items in < 2 seconds single threaded on the old, weak laptop I use at work.
We need details if you need to do something exotic, but do not let a number in the low millions worry you. It will most likely fit entirely in ram in one block, and can be processed at astonishing speeds. If its too large to put into ram, it may requires 10s of seconds instead, but even so, are you concerned about the time it will take, or something else?
You could also add an overloaded operator < to struct PR.
Later you could either use a std::vector like now or insert the elements in a std::set (but this could be less efficient).
I'll take your word for it, but what file did you use, what did you call it, how did you amend the code, and what exactly do you mean by "Printed just 1 occurrence"?
If I put the contents of the stringstream in a file instead then it gives the same output as before.