[Solved] C++ : Why my string is not getting printed?
See CppReference operator [] No bounds checking is performed. If pos > size(), the behavior is undefined. When you define string r, its size() is zero, so all your character assignments are undefined behaviors. You may want to resize it first: r.resize(9); Or alternatively, append the characters one-by-one: r = “”; r.push_back(hh/10+’0′); r.push_back(hh%10+’0′); r.push_back(‘:’); r.push_back(mm/10+’0′); … Read more