how to use cin in a if statement

How do I use a if statement with cin like, if the user types ok then this would happen? I only know how to use cin and if statements if the user inputs integers, but not with strings. A example of the code would help too thanks!
 
  
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include<string>

int main()
{
    std::string choice;
    std::cin >> choice;
    if(choice == "ok")
        std::cout << "OK\n";
    else
        std::cout << "Not OK\n";
}
Topic archived. No new replies allowed.