-
October 2nd, 2002, 11:32 PM
#1
Junior Member
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.
-
October 3rd, 2002, 12:26 AM
#2
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
-
October 3rd, 2002, 12:36 AM
#3
Member
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?
-
October 3rd, 2002, 05:39 AM
#4
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
-
October 3rd, 2002, 01:28 PM
#5
Junior Member
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
-
Forum Rules
|
|