Results 1 to 5 of 5

Thread: naming stuff after user input in c++

  1. #1
    Junior Member
    Join Date
    Aug 2002
    Posts
    7

    Question naming stuff after user input in c++

    how would you name a variable after user input? As in, what syntax would you enclose input that you wanted to correspond with names in the program, so that you could allow them to(for example) create there own instance of class 'usr' (and name it after input) so that later they could enter that and call upon their own personal instance of class usr.

    If you don't quit understand what i'm asking then please post so and I will clarify with code segments and such.

    Thanks for your time.
    There are 10 types of people in this world, The ones that understand binary and the ones that dont.

  2. #2
    Webius Designerous Indiginous
    Join Date
    Mar 2002
    Location
    South Florida
    Posts
    1,123
    Well, from what i gather, you asking how one will assign a value to a variable.

    #include<iostream>
    using namespace std;

    void main()
    {
    char name[18]

    cout<<"Please enter your name"<<endl;
    cin>>name;
    cout<<"Your name is "<<name<<'.'<<endl;
    }

    That will allow a user to enter a name into the variable name.
    cheers

  3. #3
    Sounds to me like he's asking whether or not you can create a class or a variable based on a user input value, kinda like

    cout>>"Enter a variable name";
    cin<<name;

    int (name from above);

    My guess would be that the compiler is going to have a screaming fit because it doesn't know the name of the variable at compile time. The compiler is going to convert the names into references to memory addresses, so it needs to know what the name is in order to do that.

    Why do you want to dynamically create a variable or class based on a user input name? Why is that more valuable than specifying a name?

  4. #4
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    That doesn't make any sense unless you want to have helpful debugging ("Error: Valueofproduct = 0, divide by zero..."). In which case there are already various ways to do that, at the expense of making the program easier to reverse engineer or decompile.

    It's pointless, even the names you DO give objects... they all get turned into numerical representations when the program is compiled anyway! It really never matters (to the computer) what you name variables after they've been compiled.
    [HvC]Terr: L33T Technical Proficiency

  5. #5
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    redbone was right, but so was terr.......its pointless, so forget about it........thnx anyways
    There are 10 types of people in this world, The ones that understand binary and the ones that dont.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •