Change string locale
I'm not very familiar with locale-specific conversions so I may be using th开发者_StackOverflow中文版e wrong terminology here. This is what I want to have happen.
I want to write a function
std::string changeLocale( const std::string& str, const std::locale& loc )
such that if I call this function as follows:
changeLocale( std::string( "1.01" ), std::locale( "french_france" ) )
the output string will be "1,01"
Thanks for your help!
Something like this ought to do the trick
#include <iostream>
#include <sstream>
#include <locale>
int main (int argc,char** argv) {
std::stringstream ss;
ss.imbue(std::locale("fr_FR.UTF8"));
double value = 1.01;
ss << value;
std::cout << ss.str() << std::endl;
return 0;
}
Should give you output of 1,01
(at least it does on g++). You might have to fiddle with the locale specification since it's very specific to platform.
精彩评论