Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不完全知道我是否有 IDE/工具链问题、Mac 问题或 C++ 问题:
我想用ofstream. 这按预期工作。但是,当我保存到带有波浪号(如“~/Desktop/test.txt”)的文件路径时,会ofstream::good()报告错误。但是,我可以成功使用“/Users/Michael/Desktop/test.txt”之类的路径。
ofstream
ofstream::good()
这适用于 Xcode 调试器、使用 Eclipse 运行以及从控制台直接调用可执行文件。
这里的波浪号“~”有什么问题?
没有 path ~,那是你的 shell 解释的东西。您需要将其扩展为环境变量HOME设置的任何内容。
~
HOME
如果您通过 shell 调用您的工具,这将提前为您展开。如果您在 Xcode 中,则需要$HOME明确指定。
$HOME