其他分享
首页 > 其他分享> > warning C4047: ‘=‘: ‘CHAR16‘ differs in levels of indirection from ‘char [2]‘

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://stackoverflow.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'; //用单引号

问题解决。

 

标签:levels,char,C4047,warning,报错,differs,StrBuffer
来源: https://blog.csdn.net/zhouyingge1104/article/details/113761651