as you could see in the title, I am working on a vector of structs.
one of the struct members is string word.
when i am trying to enter data to this member in this way: (*iv).word=temp_str;, i get a runtime error.
while (is!=str1.end())
{
if (((*is)!='-')&&((*is)!='.')&&((*is)!=',')&&((*is)!=';')&&((*is)!='?')&&((*is)!='!')&&((*is)!=':'))
{
temp_str.push_back(*is);
++is;
}
else
{
(*iv).word=temp_str;
++iv;
str1.erase(is);
temp_str.clear();
}
}
this may be the relevant code interval.
should say- word and temp_str are of string type.
iv is an iterator to the vector.
what is the right way to enter data into a struct member in this case?
Your iterator is probably invalid, otherwise it shouldn’t be a problem assigning one string to another.
One problem is the line:
This will invalidate
is, you should probably change it to:What does
ivpoint at? It seems like you would need to add something like:as well.