C++错误:"Expression must have integral or enum type"
C++ Error: "Expression must have integral or enum type"
我得到错误"表达式必须具有整型或枚举类型"对我的(不完整)函数的switch
语句。我盯着它看了一会儿,还是不明白是怎么回事。非常感谢任何见解。
std::string CWDriver::eval_input(std::string expr)
{
std::vector<std::string> params(split_string(expr, " "));
std::string output("");
if (params.size() == 0)
{
output = "Input cannot be empty.n";
}
else
{
switch (params[0])
{
case "d":
}
}
}
错误已清除。您只能使用整型类型(integer
, enum
, char
等可转换为integral
值),或在switch
语句中计算为整型的任何表达式。
params[0]
的类型为std::string
。不能使用std::string
类型(它不是整型)作为switch
参数。如果您确信字符串不是空的,则使用switch (param[0][0])
和case 'd'
。但在这种情况下,您将只能切换单字符字符串。如果需要切换较长的字符串,则需要使用if-else if-else if-...
序列。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 模式"allocate memory or use existing data"
- N-API include an .so or dll
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 将 OR 逻辑运算符从 C++ 转换为 Fortran
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- 我如何将 OR 与 if 语句一起使用字符串
- 将 if 语句中的字符与 or 进行比较
- Google Or-Tools Glop:如何创建指向 const 对象的指针数组?
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 编译为 cuda 内核调用提供了"expression must have integral or unscoped enum type"
- 模板元编程:"does not have integral or enumeration type"
- 字符串初始化失败:"expression must have integral or unscoped enum type"
- 错误消息在 C++ 中显示为"expression must have integral or enum type"
- unordered_map关键问题"expression must have integral or unscoped enum type"
- 新手错误与"expression must have integral or enum type"
- C++错误:"Expression must have integral or enum type"