表达式必须具有整型或无作用域枚举类型
Expression must have integral or unscoped enum type
可以将两个char const*
参数相加吗?代码应该看起来像这样。我需要c
像a
和b
一样char const
。如果有人知道如何制作这个,请帮助我:)提前致谢
char const *a = "something";
char const *b = " more";
char const *c = a + b;
如果您希望字符串像其他语言中的对象一样工作,请使用std::string
。
std::string a = "something";
std::string b = " more";
std::string c = a + b;
如果需要将生成的字符串传递给需要const char *
的东西,则可以对字符串调用 c_str()
函数。
你应该有一个char
数组来创建连接的结果:
char* result;
result = static_cast<char*>( calloc ( strlen( a) + strlen( b) + 1,
sizeof( char)));
strcpy( result, a); // copy string a into the result
strcat( result, b); // append b to the result
但是,在C++中,您应该使用std::string
:
std::string a = "something";
std::string b = " more";
std::string result = a + b;
相关文章:
- 将作用域枚举转换为基础类型
- 无法让"std::enable_if"适用于无作用域枚举
- 为什么不能直接引用作用域枚举类成员,而不能为无作用域枚举生成类成员?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 作用域枚举和标准::get
- 如何确保 Visual C++ 不允许作用域枚举访问?
- C++/错误:表达式必须具有整数或无作用域枚举类型
- C++ 在方程中使用变量;错误:表达式必须具有整数或无作用域枚举类型及其他
- 防止作用域枚举可复制/可移动
- 错误:以增量方式填充向量时,表达式必须具有整数或无作用域枚举类型
- 无作用域枚举的基础类型?
- 有效的双向作用域枚举映射
- 错误:数组大小表达式必须具有整型或无作用域枚举类型,而不是'double'
- 为什么作用域枚举默认支持运算符'<'?
- 无作用域枚举、枚举器和基础类型C++中的歧义
- 为什么要编译无作用域枚举的声明?
- 具有作用域枚举的位集无法编译
- 如何重载作用域枚举的运算符>?
- 无作用域枚举是否仍然有用
- 表达式必须具有整数或无作用域枚举类型,并带有字符串向量