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

This is a discussion on How do I check if a cin string is equal to something? within the C++ Programming forums, part of the General Programming Boards category; Like this: Code: int string; cin>>string; if(string is "lol") How would I do that?...

  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
    ZuK
    ZuK is offline
    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, 01: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, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21