Help with string inputs on if statements

I'm trying to figure out how to make an input with a string thats part of an if statement.

how i think it should be done
#include <iostream>
#include <string>
using namespace std;

int main()
{
string choose;

cout << "Please choose: ";
cin >> choose;

if ((choose = 'ss') || (choose = 'SS'))
{
do this stuff
}
if ((choose = 'aa') || (choose = 'AA'))
{
do this other stuff
}
}


but i get a strange warning (not an error, but something that is like "just letting you know" i suppose)
and when i enter in ss or SS or aa or AA, it breaks my app.
closed account (3hM2Nwbp)
The warning that you're getting is likely emitted from using multi-byte characters. Character literals may only consist of a single character. Perhaps you should use a std::string instead?
Last edited on
i thought std::string and string where the same? you only include std:: on the front if you dont have using namespace std;
closed account (3hM2Nwbp)
if(choose.compare("SS") == 0) ... is what I meant. 'SS' is invalid.
so what if SS is valid? 0 would be 1?
weird, the warning im getting is "multi-character character constant"
but i dont have it defined as a character, i have it defined as a string
closed account (3hM2Nwbp)
You can read the full story here, but simply put, if the strings are equal, the method returns 0. http://www.cplusplus.com/reference/string/string/compare/
yeah, this is saying if you already defined string.
my string is undefined until it gets user input.
Topic archived. No new replies allowed.