Assuming:
std::string ToShow,NumStr;
The following displays “This is 19 ch00”:
ToShow = "This is nineteen ch";
ToShow.resize(ToShow.length()+0);
NumStr = "00";
ToShow += NumStr;
mvaddstr(15,0,ToShow.c_str());
And the following displays “This is 19 ch “:
ToShow = "This is nineteen ch";
ToShow.resize(ToShow.length()+1);
NumStr = "0";
ToShow += NumStr;
mvaddstr(16,0,ToShow.c_str());
In the second case, operator+= isn’t adding the string “0” to the end of ToShow. Does anyone know why?
My guess is:
You don’t specify the value to resize with, so after
ToShow.Resize(ToShow.length()+1)your string looks like:And after
+= NumStr:which, after calling c_str, gets trimmed to the first
\0and looks like:(C strings are null-terminated, std::strings aren’t)
Try calling
.resize(someLength, ' ')instead.