user550738
user550738

Reputation:

How to make a string that consists on one character '-1'?

I'm using a class that accepts commands as strings. Example ...

string cmd = "start";
connection->execute(cmd);

The 'disconnect' command is any string starting with the character '-1'. I tried doing this ...

string cmd = "0";
cmd[0] = '-1';
connection->execute(cmd);

But that produced this error ...

warning: multi-character character constant [-Wmultichar]

... how do I create a string that starts with char '-1'?

Upvotes: 0

Views: 76

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103751

Just remove the quotes.

cmd[0] = -1;

Upvotes: 1

Related Questions