Windows 10 1704 控制台程序 中文显示多出空格或乱码
从14393升级到15063之后,我发现以前在visual studio 2017里面编译的控制台程序使用cout输出的每个中文汉字后面都多了一个空格,“就 像 这 样 ”,英文不受影响,系统自带的提示(如请按任意键继续)也不受影响。而之前在14393版本下程序输出完全正常。
我首先怀疑是系统环境的问题。于是我在另一台电脑上格式化硬盘并新全新安装了Windows 10 15063,发现此问题依然存在。
我又怀疑是编译器设置有问题。于是我在他人运行14393的电脑和运行15063的两台电脑上分别用visual studio 2015编译了两个控制台程序,放到14393下运行正常,而两个程序在15063下仍然由上述问题。
因此可以初步判断,这是15063系统本身的问题,与用户开发环境无关。
更新:在至少五台电脑上进行了测试,都有此问题。
更新:用printf()输出显示正常,而用cout显示错误。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main() {
char test[] = "测试中文";
printf("%s\n",test);
cout << test << endl;
cout << (int)test[0] << endl;
cout << (int)test[1] << endl;
cout << (int)test[2] << endl;
cout << (int)test[3] << endl;
cout << (int)test[4] << endl;
cout << (int)test[5] << endl;
cout << (int)test[6] << endl;
cout << (int)test[7] << endl;
system("pause");
return 0;
}
以下为在14393下的运行结果(正常)
测试中文
测试中文
-78
-30
-54
-44
-42
-48
-50
-60
请按任意键继续. . .
以下为在15063下的运行结果(printf正常,cout错误)
测试中文
测 试 中 文
-78
-30
-54
-44
-42
-48
-50
-60
请按任意键继续. . .
以下为在15063下,将编译器输出编码改为UTF-8,控制台 chcp 65001 的运行结果(均正常)
测试中文
测试中文
-26
-75
-117
-24
-81
-107
-28
-72
Press any key to continue . . .
以下为在15063下,改用GNU GCC编译器编译(使用WINDOWS-936)的运行结果(printf正常,cout乱码)
测试中文
测灾形?
-78
-30
-54
-44
-42
-48
-50
-60
请按任意键继续. . .