我很想知道我有这个特殊的代码包
char* usage()
{
static char errors[] = {"Sorry Invalid Option entered\nPlease Enter an appropriate option"};
return errors;
}
我已经正确地调用了这个函数,它做了我想要的。然而,只要我这样做......我就会遇到很多错误。
char* usage()
{
static char errors[] = {"Sorry Invalid Option entered\n
Please Enter an appropriate option"};
return errors;
}
我所做的只是将第二行放在下面一行,我得到了错误。现在,我只想知道两者之间有什么区别?我似乎在两个字符数组中输入了相同的参数。是因为我没有为数组分配空间吗?
最佳答案
C 和 C++ 不以这种方式支持多行字面量,但您可以这样使用:
char* usage()
{
static char errors[] = {"Sorry Invalid Option entered\n"
"Please Enter an appropriate option"};
return errors;
}
注意额外的引号!
关于c++ - 从函数返回字符串....限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15556215/