[英]IntelliSense: expression must have integral or enum type
Guys i need someone fix this problem ? 伙计们,我需要有人解决这个问题吗? when i compile that code i have this error: 当我编译该代码时,出现以下错误:
Error: IntelliSense: expression must have integral or enum type
i have problem in this part: 我在这部分有问题:
Console(0, V("seta sv_hostname " + servername + ";\n"));
so how i can fix that 所以我该如何解决
if (strncmp(command, V("exec config_mp"), 14) == 0)
{
if (GAME_MODE == 'D')
{
CIniReader iniReader(V(".\\teknogods.ini"));
char *servername = iniReader.ReadString(V("Settings"),V("Servername"),"");
if (strcmp(servername,"") == 0)
{
info("Server name set to defult.");
}
else
{
//Console(0, V("seta scr_teambalance 1;\n"));
Console(0, V("seta sv_hostname " + servername + ";\n"));
info("server name set to: %s.", servername);
}
}
}
You cannot concatenate two C strings with +
. 您不能用+
连接两个C字符串。
In C and C++ string literals are arrays of characters, which when used as rvalue in an expression decay into a pointer to the character. 在C和C ++中,字符串文字是字符数组,当在表达式中用作右值时,它会分解为指向字符的指针。 In C (and C++) you can perform pointer arithmetic, which means that you can add or substract an integer (or any integral type) from a pointer and you can also substract two pointers to obtain a difference, but you cannot add two pointers together. 在C(和C ++)中,您可以执行指针算术,这意味着您可以从指针中添加或减去整数(或任何整数类型),还可以减去两个指针以获得差值,但是不能将两个指针加在一起。 The expression "A" + "B"
is incorrect as that would try to add two const char*
. 表达式"A" + "B"
不正确,因为它将尝试添加两个const char*
。 That is what the compiler is telling you: for the expression "seta sv_hostname " + servername
to be correct, servername
must be either an integer or an enum. 那就是编译器告诉您的:为了使表达式"seta sv_hostname " + servername
正确, servername
必须是整数或枚举。
If coding C++ you can use std::string
, for which there are overloaded operator+
that take either another std::string
or const char*
and then use the c_str
member function to retrieve a const char*
to use in interfaces that require C strings. 如果使用C ++进行编码,则可以使用std::string
,为此,其中有重载的operator+
会使用另一个std::string
或const char*
,然后使用c_str
成员函数检索const char*
以在需要C字符串的接口中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.