User inputs from cin inside if statement


I am trying to do user input where a user types in "d(i)" where 'i' is a variable when the user wants to delete the i-th element.

In my if-statement, I have this:

char i;

std::cin >> i;

if(i == 'q'){
else if(i == 'd(' i ')'){ // Problem

But this doesn't work. I've tried other methods but can't get it to work. Any help guys?

You want the user to enter a string not a single character. So use string i instead and replace your single quotes ' ' with double quotes " "
Hey, Thanks a bunch. It works, but I am having problems to detect input of i:

For example in my if statement:

else if(i == "d(i)"){
u.remove(u.get(i)); //Here, it reads in i from d(i)

Now, it can't call the get method for i when user enters "d(i)"
Topic archived. No new replies allowed.