Arrays and strings

Dec 7, 2011 at 6:34pm
Hey guys, I'm trying to pass a string into a string into a public member function and I can't get it to work.

From main:

string Array;
cout << "Enter all of tghe answers without spaces: ";
cin >> Array;
Test.setKey(Array);


From class function:

void TestGrader::setKey(string ANS)
{
for(int i = 0; i < 20; i++
{
answer[i] = ANS[i];
}
}


Any help would be much appreciated!
Last edited on Dec 7, 2011 at 6:38pm
Dec 7, 2011 at 6:47pm
What do you expect this to do, and what is actually happening? (If you just want to copy the string, you can just do answer=string if answer is a std::string).
Last edited on Dec 7, 2011 at 6:47pm
Dec 7, 2011 at 7:00pm
I'm trying to pass elements of a string into an array
Dec 7, 2011 at 7:24pm
What do you want to happen, and what is happening? It's a bit hard to understand if you write that little.
Topic archived. No new replies allowed.