关于MinGW的宽字符串输出问题
用 MinGW编译器,想打印一个“你好,世界”。真折腾,到现在还没解决,:dizzy:
有谁清楚吗,Help!! 找到一种可行的方案了:#include <iostream>
using namespace std;
int main(){
wcout << setlocale(LC_ALL, "chs" )
<<endl<<L"还是不行吗" << endl;
}g++ test.cpp -finput-charset=GBK
#include <string>
#include <locale>
using namespace std;
void main()
{
unsigned int n, d;
int pre, i, high, low;
wchar_t c = L"零一二三四五六七八九";
wchar_t p = L"个十百千万十百千亿";
for (i = 0; i < 9; i ++) d = 0;
cout << "请输入数字 :";
cin >> n;
if (n >= 1000000000)
{
cout << "输入数字过大"<<endl;
exit(1);
}
i = 0;while (n > 0)
{
d = n % 10;
n /= 10;
}
high = i-1; //最高位
low = 0; //最低位 while (d == 0)low ++;locale loc( "chs" );
wcout.imbue(loc);
cout << endl << "大写形式:";if (n == 0) { cout << "零" << endl; exit(0); } //特殊处理零
pre = 0;
for (i = high; i >= low; i --)
{
if (d > 0)
{ wcout << c]; if (i > 0)wcout << p;}
else
if (pre)
wcout << L"零";
pre = (d != 0);
}
} 这个帖子要收藏一下,以后用得到
页:
[1]