Xcode 5 c++ fstream(ifstream 和 ofstream)不起作用

Xcode 5 c++ fstream (ifstream and ofstream) do not work

本文关键字:ofstream 不起作用 ifstream c++ fstream Xcode      更新时间:2023-10-16

所以我正在尝试读取应用程序的内容文件夹中的文件内的内容:

std::string username;
std::ifstream user("../Resources/username.txt");
user >> username;
user.close(); /*here I do a breakpoint to check the value of username and it's ""*/

我做一个"如果"来检查文件是否打开,这显然不是可以的。 你告诉我我做错了什么(我知道文件路径及其名称是正确的 我使用 SDL2 等对图像上传等使用了类似的过程)

试试这个:

std::string username;
std::ifstream user("C://test.txt", std::ifstream::in);
user >> username;
user.close(); /*here I do a breakpoint to check the value of username and it's ""*/