Problems with using vector of characters and string concatenation

Revision en3, by I_lOVE_ROMAN, 2023-07-06 23:28:15

I have a string which is empty initially.Then I added characters to it.

string s="";
s=s+'a';

it works fine in my pc but getting error in codeforces submission because it prints garbage at the end of hathe printed string.

Same things happen I use vector of char.In that case I use push_back method to add chars.But it still prints garbage in codeforces submission.

vector<char>vc;
vc.push_back('a')

Why is that happening? /predownloaded/42/08/4208fdc2b1a8d618adc8327184077c6b4baa0b60.png

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English I_lOVE_ROMAN 2023-07-06 23:28:15 1 Tiny change: 'Why is tha happening' -> 'Why is that happening'
en2 English I_lOVE_ROMAN 2023-07-06 23:27:34 69 Tiny change: 'ppening?\n\n\n\n' -> 'ppening?\nhttps://codeforces.com/796a07/Capture.PNG\n\n\n\n\n'
en1 English I_lOVE_ROMAN 2023-07-06 23:26:13 546 Initial revision (published)