0

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());
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jennifer84
0

>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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.