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
Post a Comment