use*_*171 4 c++ printing ofstream quotations
我需要打印一个完全正确的字符串:
std::string("-I\"/path/to/dir\" ");
Run Code Online (Sandbox Code Playgroud)
基本上,我需要这样做,因为我使用C++代码生成C++代码.
我想通过ofstream编写上面的字符串,所以像
ofstream fout;
fout << the_string << endl;
Run Code Online (Sandbox Code Playgroud)
问题是我不能\\"在字符串里面做.
只是逃避斜线和报价!即\"- >\\\"
fout << "std::string(\"-I\\\"/path/to/dir\\\" \");" << std::endl;
Run Code Online (Sandbox Code Playgroud)
在C++ 0x/C++ 11中
fout << R"(std::string("-I\"/path/to/dir\" ");)" << std::endl;
Run Code Online (Sandbox Code Playgroud)
它使用原始字符串文字 1
1毫无疑问,ideone.com和stackoverflow的语法高亮显示器尚未准备好:)
| 归档时间: |
|
| 查看次数: |
22155 次 |
| 最近记录: |