如何修复"no suitable conversion function from "字符串" to "常量字符* " exists"?
How to fix "no suitable conversion function from "String" to "const char *" exists"?
我不完全确定如何完成此操作,我已经搜索并尝试了许多不同的事情,但我就是无法让它工作? strcpy(host, DATA);是给我错误的原因。
char host[60] = "www.yahoo.com";
void loop() {
String content = "";
char character;
while (Serial.available()) {
character = Serial.read();
content.concat(character);
}
if (content != "") {
String CMD = getValue(content, '|', 0);
String DATA = getValue(content, '|', 1);
if (CMD == "SSID")
{
Serial.println("Your CMD is:" + CMD + " And your DATA is:" + DATA);
}
else if (CMD == "PASS")
{
Serial.println("Your CMD is:" + CMD + " And your DATA is:" + DATA);
}
else if (CMD == "HOST")
{
Serial.println("Your CMD is:" + CMD + " And your DATA is:" + DATA);
strcpy(host, DATA);
}
}
delay(100);
}
如果String
,是一个std::string
,你可以做
strcpy(host, DATA.c_str());
例如,如果是自定义类
class String
{
char buffer[20];
//add a method c_str() for example like the std::string does
const char * c_str() { return buffer; }
//or just go yolo and overload the operator const char * like a boss
operator const char *() { return buffer; }
};
您现在要做的就是strcpy(buff, DATA)
并使用operator const char * ()
。
相关文章:
- "error: no matching function for call to"构造函数错误
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 什么时候在C++中返回常量引用是个好主意
- 代理对象的常量正确性
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 通过多个头文件使用常量变量
- 调用专用模板时出错"no matching function for call to [...]"
- C++ Singleton - Prevent ::instance() to variable
- 在cuda线程之间共享大量常量数据
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 是默认情况下分配给char数组常量的值
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 私有类型的静态常量成员
- 类似枚举的计算常量
- 递归模板化函数不能分配给具有常量限定类型"const tt &"的变量"state"
- 如何修复"no suitable conversion function from "字符串" to "常量字符* " exists"?