Thread: Strings and things!

  1. #1
    Shadow12345
    Guest

    Strings and things!

    how do i get this to work??


    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
    string name;

    cin >> name;

    if (name == 'hi')
    {
    cout << "\nHELLO THERE!!";
    }
    else
    {
    cout << "\nYou didnt say hi!";
    }
    return 0;
    }

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Replace 'hi' with "hi"
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User Dr. Bebop's Avatar
    Join Date
    Sep 2002
    Posts
    96
    You used single quotes around the test string instead of double quotes.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
            string name;
            
            cin >> name;
            
            if (name == "hi")
            {
                    cout << "\nHELLO THERE!!";
            }
            else
            {
                    cout << "\nYou didnt say hi!";
            }
            return 0;
    }
    Processing error: Stupidity detected.
    ------------------------------
    Dr. Bebop
    Windows XP Professional Ed.
    Microsoft Visual Studio 6

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Heh, that was a close one.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question: Stream I/O (working with strings)
    By ckuttruff in forum C Programming
    Replies: 15
    Last Post: 05-19-2008, 11:32 AM
  2. Replies: 9
    Last Post: 03-17-2006, 12:44 PM
  3. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  4. Need Help With Strings N Things
    By joxerjen in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2005, 11:18 AM
  5. cin strings till eof
    By bfedorov11 in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2003, 07:27 AM