char message[512];
string info;
...
// read from txt file and save to "info"
...
message = info.c_str();
错误是由最后一行的“消息”引起的。我不熟悉C或C ++,有人能告诉我出了什么问题吗?
答案 0 :(得分:2)
const char *message; // needs to be a pointer, not an actual array
string info;
...
// read from txt file and save to "info"
...
message = info.c_str();
答案 1 :(得分:1)
你可以这样做:
strncpy(message, info.c_str(), sizeof(message));
message[sizeof(message) - 1] = '\0';