help with chars...

This is a discussion on help with chars... within the C++ Programming forums, part of the General Programming Boards category; hi all, i was just wondering if it was posible to create a char with a name enter by the ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    35

    Question help with chars...

    hi all,

    i was just wondering if it was posible to create a char with a name enter by the user e.g.

    if the user enters 'welcome' it will create a char called 'welcome' for example

    Code:
    char name_entered_by_user[255]
    thx for any help just ask if ur not clear on what i mean
    Theres a sucker born every minute, but a swallower is harder to find

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Nope, not possible with C++ as you want it. However, you can kind of fake it with a map
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    
    using namespace std;
    
    int main()
    {
        map<string, string> strings;
    
        // Assume the names are entered interactively ;)
        strings["beep"] = "Beep!";
        strings["boop"] = "Boop!";
        strings["snic"] = "Snickerdoodle!";
    
        map<string, string>::iterator i;
        for (i = strings.begin(); i != strings.end(); ++i)
            cout<< i->second <<endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while condition question..
    By transgalactic2 in forum C Programming
    Replies: 3
    Last Post: 04-04-2009, 05:49 PM
  2. Counting how many chars in a string
    By tigs in forum C Programming
    Replies: 4
    Last Post: 08-05-2002, 01:25 AM
  3. really got stuck with unsigned chars
    By Abdi in forum C Programming
    Replies: 7
    Last Post: 06-11-2002, 01:47 PM
  4. move chars position
    By SpuRky in forum C Programming
    Replies: 3
    Last Post: 06-09-2002, 03:59 AM
  5. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 05:29 PM

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