Thread: Typing Words.

  1. #1
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079

    Typing Words.

    Is there a way to make a program respond to words? Like for instance, if I have this in a program:

    Code:
    cin >> comm;
    
                   if ( comm = "North" ) {
    or would it be more like:

    Code:
    cin >> comm;
    
                   if ( comm = North ) {
    ...or am I just dreaming that it would be that simple?

    Here is the error I get with this:

    " invalid conversion from `const char*' to `char' "

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Just use the string class, then you can use ==
    Otherwise, you'd have to use the likes of strcmp()
    Code:
    #include <iostream>
    #include <string>
    
    int main() {
        std::string bar;
        bar = "hello";
        if ( bar == "hello" ) {
            std::cout << "Woo!" << std::endl;
        }
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM