1. You can't. Variable names go away in compiled code. They are just useful for the programmer to give names to things in the source code. The computer doesn't need names to execute code.
2. Keep a mapping of names and values for the user.
#include <iostream>
#include <map>
#include <string>
usingnamespace std;
int main()
{
map <string, string> environment;
cout << "Enter a list of variables as 'name=value'.\n""Press ENTER when asked for a name to quit.\n";
while (true)
{
cout << "name> ";
string name;
getline( cin, name );
if (name.empty()) break;
cout << "= ";
string value;
getline( cin, value );
environment[ name ] = value;
}
cout << "\nGreat! Your names and values are:\n";
for (auto e : environment)
{
cout << e.first << " = " << e.second << "\n";
}
}