I'm trying to generate a string of 50 dots. I have the following code:
#include <string> using namespace std; int main(){ string s(".",50); cout << s; } and the output is:
.vector::_M_realloc_insert$C����pX�% The string s doesn't store . 50 times, but some other part of memory. A leak happened, and I have no idea how.
What went wrong? How do I go about generating a string of length n consisting only of dots? In general, I want to do in c++ what in python would be done by "c"*n.
Thank you.
std::string s(50, '.');. And next time, please remove anything irrelevant (i.e. 95% of it) from the code you post, see minimal reproducible example.