#include <iostream>
#include <limits>
#include <locale>
struct space_out : std::numpunct<char> {
    char do_thousands_sep()   const { return ' '; }   // separate with spaces
    std::string do_grouping() const { return "\1"; } // groups of 1 digit
};
int main()
{
    int n;
    while(!(    std::cout << "Enter a three-digit integer: "
             && std::cin >> n
             && n > 99 && n < 1000))
    {
        std::cin.clear();
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cout << "This was not a three-digit integer, try again\n";
    }

    std::cout.imbue(std::locale(std::cout.getloc(), new space_out));
    std::cout << n << '\n';
}
