Through assign, it works correctly, that is, it adds to the existing one, and sometimes it just overwrites, and through + = it is always good. It does not work (overwrites) a code like this:

string namebuffer; for(list<vector<string> > :: iterator i = m_AccPassList.begin(); i != m_AccPassList.end(); i++) namebuffer.assign( (*i)[0] ); 

And if namebuffer+= (*i)[0]; it works. What could be the problem?

  • You confuse assign and append. - VladD

1 answer 1

http://www.cplusplus.com/reference/string/string/assign/

Replacing its current contents .

assign just overwrites the content. If concatenation is needed, i.e. string concatenation, then use the "+" operator.