Reputation: 5637
I wonder what happen here ?? Please advice
I'm not familiar with c++ can't I do like this ?
char result = (msg[0] == 0) ? "OFF" : "ON";
printf("A/C is " + result + "\n");
Upvotes: 0
Views: 1279
Reputation: 409432
First of all you can't simply use the addition operation to concatenate C-style strings, second of all you should be using std::cout
for output:
std::cout << "A/C is " << result << '\n';
If you want to concatenate strings, at least one string have to be a std::string
object.
Upvotes: 0
Reputation: 33944
It looks like you should be using streams
.
std::cout << "A/C is " << result << std::endl;
Upvotes: 0
Reputation: 223153
You should use:
printf("A/C is %s\n", result);
Your result
is actually declared with the wrong type; it should be char const *
.
Even better (as mentioned in Ed's comment), you shouldn't be using printf
for this. Do this instead:
std::cout << "A/C is " << result << "\n";
Upvotes: 3
Reputation: 87486
Apparently you cannot. Try this:
const char * result = (msg[0] == 0) ? "OFF" : "ON";
printf("A/C is %s\n", result);
Upvotes: 1