using user input as a var.

This is a discussion on using user input as a var. within the C++ Programming forums, part of the General Programming Boards category; Hey i was wondering if there was anyway to take a 'string' and use it in place of an int/char ...

using user input as a var.

Hey i was wondering if there was anyway to take a 'string' and use it in place of an int/char or whatever.

ie

Code:

cout<<"Type in what kind of shape you would like.\n";
cin>>Shape_Name;
Draw(Shape_Name);

Im not sure if that makes sense...but lets say ive got a large program with many 'shape instances' and I dont want to make a huge 'switch/case'. So instead of 'switch/case' I just take user input and somehow change it into a 'variable' and pass it into a function.

*shrugs*maybe that is a foolish request, but if that were possible...man that would open up a whole new world to me =/

"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush

There is no way to do such things in C/C++, because of the ways that C/C++ processes it and AS IT COMPILES IT. BASH and PERL (i think you can do it in PERL too) are (mostly) interpreted, which makes it easier to do this. The only way that I could see doing this would be something along the lines of using user unput as one of the fields of a template class:

ohhh ok, now i understand what you are asking. unfortunatly, i dont know how to help you. ill look around, and if i find anything, ill post. i could have sworn i saw something on the subject a while ago, but it seems to have disappeared. maybe that was another site.

"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush

Opinion

I think that you can not use templates like that. Templates are not dynamic polimorphic. They are "configured" at compiling time. Uh! No good telling how things works.
Anyway. You could use polimorphism(I donīt know how to write it correct) like this.