nomnom
nomnom

Reputation: 1638

C++: expression must be a modifiable lvalue

char message[512];
string info;
...
// read from txt file and save to "info"
...
message = info.c_str();

The error is caused by "message" on the last line. I'm not familiar with C or C++, can someone tell me what went wrong?

Upvotes: 0

Views: 817

Answers (2)

Viktor Simkó
Viktor Simkó

Reputation: 2627

You can do this:

strncpy(message, info.c_str(), sizeof(message));
message[sizeof(message) - 1] = '\0';

Upvotes: 1

Gavriel
Gavriel

Reputation: 19237

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();

Upvotes: 2

Related Questions