Function that adds commas between groups of 3 digits in a string
Avoid using namespace std

The standard namespace isn't designed to be imported wholesale, and name collisions could later appear that silently change the meaning of your program (such as when you add an extra include, or move to a newer C++ standard).

std::string::insert moves content multiple times

We're not very efficient, because the later characters will be shuffled as many times as there are preceding commas inserted.  Worse, we don't even reserve() enough space to add the commas, so there could (theoretically at least) be multiple memory allocations.

Don't reinvent the wheel

It would be simpler and more flexible to use std::numpunct to perform the formatting.