0
Three digit separator program in c++
C++
3 odpowiedzi
+ 8
Hello, Welcome to SoloLearn! 😊
Please, specifying your question correctly!?
Use the search bar!
https://www.sololearn.com/post/10362/?ref=app
Posts in Q/A section should be programming-related and aimed at helping individual learners and community members improve their programming skills!
Please, read our guidelines:
https://www.sololearn.com/discuss/1316935/?ref=app
An useful code for any new user here!;)
https://code.sololearn.com/WvG0MJq2dQ6y/
+ 5
It can be easily done using std::numpunct like so ¹
#include <iostream>
#include <locale>
struct space_out : std::numpunct<char> {
char do_thousands_sep() const { return '.'; } // separate with dot
std::string do_grouping() const { return "\3"; } // groups of 3 digits
};
int main()
{
std::cout << "default locale: " << 12345678 << '\n';
std::cout.imbue(std::locale(std::cout.getloc(), new space_out));
std::cout << "locale with modified numpunct: " << 12345678 << '\n';
}
Output:
default locale: 12345678
locale with modified numpunct: 12.345.678
_____
¹ https://en.cppreference.com/w/cpp/locale/numpunct/thousands_sep
+ 1
Show us your attempt.