I need to print a string that says exactly:
std::string("-I\"/path/to/dir\" ");
Basically, I need to do this because I am using C++ code to generate C++ code.
I want to write the above string via an ofstream, so something like
ofstream fout;
fout << the_string << endl;
The problem is that I cannot do \\"
inside a string.
Just escape the slash as well as the quotes! I.e.
\"
-->\\\"
in C++0x/C++11
which uses a raw string literal1
See both versions tested live at http://ideone.com/TgtZK
1 For which unsurprisingly the syntax highlighters for ideone.com and stackoverflow are not yet prepared :)