warning C4047: ‘=‘: ‘CHAR16‘ differs in levels of indirection from ‘char [2]‘

调试C程序,报错:warning C4047: '=': 'CHAR16' differs in levels of indirection from 'char [2]'

代码如下:

CHAR16 StrBuffer[3] = {0};
...
StrBuffer[0] = Key.UnicodeChar;
StrBuffer[1] = '\n';
StrBuffer[2] = "G"; //报错!

当给StrBuffer赋值字符串"G"的时候报错。网上找到了答案:

https://*.com/questions/47447365/warning-c4047-char-differs-in-levels-of-indirection-from-char-2/47447389

原来,用双引号的"G"是字符串字面量( string literal),如果需要字符常量(character constant)的话,就用单引号:

StrBuffer[1] = '\n';
StrBuffer[2] = 'G'; //用单引号

问题解决。

 

上一篇:python-在日志中记录异常


下一篇:[docker] 更改docker默认存储位置最简单的方法——软连接