Problems with using vector of characters and string concatenation

Правка en1, от I_lOVE_ROMAN, 2023-07-06 23:26:13

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 tha happening?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский I_lOVE_ROMAN 2023-07-06 23:28:15 1 Tiny change: 'Why is tha happening' -> 'Why is that happening'
en2 Английский I_lOVE_ROMAN 2023-07-06 23:27:34 69 Tiny change: 'ppening?\n\n\n\n' -> 'ppening?\nhttps://mirror.codeforces.com/796a07/Capture.PNG\n\n\n\n\n'
en1 Английский I_lOVE_ROMAN 2023-07-06 23:26:13 546 Initial revision (published)