gpt4 book ai didi

c++ - 有没有办法从字符串输出cout中的反斜杠符号?

转载 作者:行者123 更新时间:2023-12-02 09:49:32 30 4
gpt4 key购买 nike

C++代码

fs::path pathToShow("C:\Windows\system.ini");
cout << "exists() = " << fs::exists(pathToShow) << "\n"
<< "root_name() = " << pathToShow.root_name() << "\n"
<< "root_path() = " << pathToShow.root_path() << "\n"
<< "relative_path() = " << pathToShow.relative_path() << "\n"
<< "parent_path() = " << pathToShow.parent_path() << "\n"
<< "filename() = " << pathToShow.filename() << "\n"
<< "stem() = " << pathToShow.stem() << "\n"
<< "extension() = " << pathToShow.extension() << "\n";

摘自 https://www.codingame.com的示例

输出量
exists() = 0
root_name() = "C:"
root_path() = "C:"
relative_path() = "Windowssystem.ini"
parent_path() = "C:"
filename() = "Windowssystem.ini"
stem() = "Windowssystem"
extension() = ".ini"
Press any key to continue . . .

Visual Studio是否具有编译器/链接器选项来威胁'\'符号为
\\

用cout或printf输出时?还是有另外一种简单的方法,而无需创建自己的函数来操作字符串(无需太费劲)?

最佳答案

不是编译器选项,而是语言功能:使用raw string literal。应该适用于所有编译器。

fs::path pathToShow(R"(C:\Windows\system.ini)");

关于c++ - 有没有办法从字符串输出cout中的反斜杠符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61361499/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com