int main() { string s = "Hello\t\0world"; string k = ""; for(auto i =0; i<s.length();i++){ switch(s[i]){ case '\t': k = k + "\\t"; break; case '\0': k = k + "\\0"; break; default: k = k + s[i]; } } cout<<k; return 0; } After null character string is ending and not able to get full solution.
Output should be: Hello\t\0world
\\0