#include <iostream>
#include <string>

int main()
{
	std::string str = "t\tt\\";

	std::cout << "Before: " << str << std::endl;
	
	std::string::size_type pos = 0;
	while ((pos = str.find_first_of("\t\n\\", pos)) != std::string::npos)
	{
    	switch (str[pos])
	    { 
    	    case '\t':
        	    str.replace(pos, 1, "\\t");
            	pos += 2;
	            break;
    	    case '\n':
        	    str.replace(pos, 1, "\\n");
            	pos += 2;
            	break;
	        case '\\':
    	        str.replace(pos, 1, "\\\\");
        	    pos += 4;
            	break;
		}
	}

	std::cout << "After: " << str << std::endl;

	return 0;
}