Thread: How do I check if a cin string is equal to something?

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    How do I check if a cin string is equal to something?

    Like this:
    Code:
    int string;
    cin>>string;
    
    if(string is "lol")
    How would I do that?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You cannot compare int's and strings
    if it's strings you want to compare it's this

    Code:
    string some_string;
    cin>>some_string;
    
    if(some_string ==  "lol")
    Kurt

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    your string is an int!
    char string[100] = "lol" //use this for c style strings
    then use strcmp(string,"lol") //defined in <cstring> header

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 02:18 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  4. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  5. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM