Hey guys, I'm reading data from a text file into a vector of strings and would like to pass these strings as parameters to a function. To be clear, I don't want to pass the actual strings as parameters, but the variable with the name which corresponds to the contents of each string.

I.e. I have a string containing the word "height" and a second string containing the word "age", I need to pass variables (of type int) called "height" and "age" to the same function for evaluation, depending on which one the user specifies in the data file. I'm not sure if this is possible, I've read something about using a map from strings to pointers but I'm not quite sure how to proceed. Any advice would be greatly appreciated.

Cheers

Edited 7 Years Ago by darkpeakjim: n/a

If I'm understanding your correctly, you basically want to use the words inside the string to define what int's are sent to the function. IE.

string one= "Height = 5'9";
string two = "Age = 20";

functionCall(x, y); // where x and y equal the values (5'9 and 20)...

If I'm understanding your correctly, you basically want to use the words inside the string to define what int's are sent to the function. IE.

string one= "Height = 5'9";
string two = "Age = 20";

functionCall(x, y); // where x and y equal the values (5'9 and 20)...

Note quite, more like this...

int height = 5
int age = 20
//read data from a file into a string, such that myString = "height" or myString = "age" depending on the user input in the file.
functionCall(myString)
return 5 or 20 respectively

Edited 7 Years Ago by darkpeakjim: n/a

This article has been dead for over six months. Start a new discussion instead.