0

I have a multiple arguments of type

string m_strVar1 = "var1";
string m_strVar2 = "var2";
string m_strVar3 = "var3";
// i have like above like 10 variables.


for(int i = 1; i < 10 ; i++) {
string strArg = "m_strArg";
std::stringstream lStream;
lStream << argCnt;
strArg.append(lStream.str());
cout << "first argument is " << strArg.c_str() << endl;

// call the function
func1(strArg.c_str());
}


///////////////

void func1(string& arg1) {
    // here i am expecting to access m_strVar1/2 value, depending on argument but value is not shown.
}

I think i am doing some thing wrong. can u please correct me. How can we achieve for calling the function with out calling 10 times with differnt values.

1
  • what you try to do here? send "var1" as parameter or what.. Commented Feb 17, 2011 at 14:48

1 Answer 1

1

If I understand your code correctly, you're passing the name of the variable as a string, or something like that.

Instead use an array of strings, eg

string m_strVar[3] = { "var1", "var2", "var3" };
for (int i = 0; i < 3; i++)
    funct(m_strVar[i]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.