Simply use replaceApp() function that can be found at: http://www.cppreference.com/wiki/string/basic_string/replace
Then code can look as:
string s1 = "This is a test with a tab\\ta breakline\\nand apostrophe '";
string s2 = s1;
s2 = replaceAll(s2, "'", "''");
s2 = replaceAll(s2, "\\t", "'$7'");
s2 = replaceAll(s2, "\\n", "'$10'");
cout << "'" << s2 << "'";
Of course changes '\t' -> '$7' can be saved in some structure that you can use in loop instead of replacing each item in separate lines.
Edit:
Second solution (example taken from comment) with using map:
typedef map <string, string> MapType;
string s3 = "'This is a test with a tab'#9'a breakline'#$A'and apostrophe '''";
string s5 = s3;
MapType replace_map;
replace_map["'#9'"] = "\\t";
replace_map["'#$A'"] = "\\n";
replace_map["''"] = "'";
MapType::const_iterator end = replace_map.end();
for (MapType::const_iterator it = replace_map.begin(); it != end; ++it)
s5 = replaceAll(s5, it->first, it->second);
cout << "s5 = '" << s5 << "'" << endl;