char数组的初始化字符串太长。在Xcode中将编译源设置为Objective-C++之后

punde 发布于 2019-03-09 ios 最后更新 2019-03-09 14:37 0 浏览

我创建了一个新的单视图项目来测试它。在我的ViewController.m里面是代码: 我不知道为什么当我将我的编译源设置为ObjectiveC++时,它给了我这个错误?字符数组的初始化字符串太长

static const char _basex[3] = "12"; <-This is always ok
static const char _basex2[2] = "12"; <-Gives the initializer error when compiler set to Objective-C++
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
已邀请:

sit_id

赞同来自:

C字符串文字"12"有3个字符,12和空终止符。 如果要初始化2 char数组,请执行以下操作: static const char _basex2 [2] = {'1','2'};