Here I am putting 2 Number into a std::vector<double> and sort these numbers like this.
When putting Number1 and Number2 wich are declared variables into the vector, the Number 5 and 10 are put into the vector.

If I after the sort write this: Numbers[0], this will give me the value of 10 with from the beginning was the variable: Number2.

What I wonder is if it is possible to receive the variablename again from the sorted vector.

Is it possible to find the variablename from Numbers[0] wich is Number2 ?

std::vector<double> Numbers;
double Number1 = 5;
double Number2 = 10;

Numbers.push_back(Number1 );
Numbers.push_back(Number2 );

//Sort the vector
std::sort(Numbers.begin(), Numbers.end());

Recommended Answers

All 2 Replies

>Is it possible to find the variablename from Numbers[0] wich is Number2 ?
Not easily, no. The variable name is a symbol that's not available at runtime unless you store it as a string in memory. Perhaps I can give a more helpful answer if you explain what problem you're trying to solve by retrieving the variable name. Most likely I can offer an alternative approach.

Thank you Narue, The problem is quite complex and I have myself found a wayaround approach to a solution that did work great.
Thank you for help !

>Is it possible to find the variablename from Numbers[0] wich is Number2 ?
Not easily, no. The variable name is a symbol that's not available at runtime unless you store it as a string in memory. Perhaps I can give a more helpful answer if you explain what problem you're trying to solve by retrieving the variable name. Most likely I can offer an alternative approach.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.