Typing Words.

This is a discussion on Typing Words. within the C++ Programming forums, part of the General Programming Boards category; Is there a way to make a program respond to words? Like for instance, if I have this in a ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    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, 09:01 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM

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