C++ string not printed -


i have next code:

void addcontent ( const std::string& message ) {    std::string newmessage;     ( int = 0, remainder = textcapacity - currenttext; < remainder; i++ ) {       newmessage[i] = message[i];       std::cout << newmessage; //here nothing printed    } } 

but nothing printed.

only if change newmessage newmessage[i] good. , dont undestand why?

newmessage empty std::string. doing [i] accessing invalid memory. string empty, , you're writing invalid memory. that's recipe disaster, , you're (un)lucky it's not crashing on you.

i'm not sure message[i] is, want newmessage[i] = message[i]. might skip temporary newmessage variable , print out message[i] itself.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -