Simply, you can't. How would you reference such a variable, anyway, which knowing what the user will input?
You don't know what the user will input, so you can't do such a thing. Why would you do it anyway ?
That's a good question with
plenty of practical uses.
You can simulate that by using a map.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <map>
#include <string>
int main()
{
std::map<std::string, int> cache;
std::cout << "Enter Cache Data Alias: " << std::endl;
std::string alias;
std::cin >> alias;
std::cout << "Enter Cache Data Value: " << std::endl;
int value = -1;
std::cin >> value;
cache.insert(std::make_pair(alias, value));
std::cout << "Attributes:\n";
for(std::map<std::string, int>::const_iterator iter = attributes.cbegin(); iter != attributes.cend(); ++iter)
{
std::cout << iter->first << " : " << iter->second << '\n';
}
std::cout << std::endl;
return 0;
}
| |
Last edited on