Three digit separator program in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Three digit separator program in c++

C++

14th Nov 2018, 12:56 PM
HATAF KHOKHAR
HATAF KHOKHAR - avatar
3 Answers
+ 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/
14th Nov 2018, 1:17 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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
14th Nov 2018, 1:59 PM
Babak
Babak - avatar
+ 1
Show us your attempt.
14th Nov 2018, 1:10 PM
HonFu
HonFu - avatar