学习笔记:setlocale

#include 

void show_current_locale_settting(){
	
	char* name = setlocale(LC_ALL,NULL) ;
	struct lconv * lc = localeconv();

	std::cout << "当前的locale设置是: " << name << std::endl;
	std::cout << "  数值的千位符是:" << localeconv()->thousands_sep   << std::endl;
	std::cout << "  货币符号是:"     << localeconv()->currency_symbol << std::endl;
	std::cout << std::endl;
}

int main()
{
	std::cout << "程序启动后: " << std::endl;
	show_current_locale_settting();
   
	std::cout << "修改货币类别相关的参数: " << std::endl;
	setlocale (LC_MONETARY,"");
	show_current_locale_settting();

	std::cout << "修改全部类别的参数: " << std::endl;
	setlocale (LC_ALL,"");
	show_current_locale_settting();

	/*
	程序启动后:
当前的locale设置是: C
  数值的千位符是:
  货币符号是:

修改货币类别相关的参数:
当前的locale设置是: LC_COLLATE=C;LC_CTYPE=C;LC_MONETARY=Chinese (Simplified)_Peo
ple's Republic of China.936;LC_NUMERIC=C;LC_TIME=C
  数值的千位符是:
  货币符号是:¥

修改全部类别的参数:
当前的locale设置是: Chinese (Simplified)_People's Republic of China.936
  数值的千位符是:,
  货币符号是:¥
	*/
}

可以只修改一个catalog,例子中是修改LC_MONETARY。所以locale查询时,需要分别枚举每个catalog对应的locale名字

你可能感兴趣的:(学习笔记:setlocale)