Comma Formatting for numbers in C++

前端 未结 5 869
北海茫月
北海茫月 2020-12-17 05:30

I\'m needing help in adding commas to the number the user enters, some guidance or help would be appreciated. So far I have it where i store the first three digits and the l

5条回答
  •  甜味超标
    2020-12-17 06:01

    Is this what you need? The locale will do this for you correctly.

    #include 
    using namespace std;
    
    int main ( int argc, char * argv[] ) 
    {
      unsigned long long userInput;
      int fthreeDigit;
      cout << "Enter a long long number: " << endl;
      cin >> userInput;
      std::cout.imbue(std::locale(""));
      std::cout << userInput << std::endl;
    
      return 0;
    }
    

提交回复
热议问题