Xcode中没有打开文本文件C ++

问题描述 投票:-1回答:1

嘿,我一直试图笔在Xcode称为“TEXT.TXT”一个文本文件,它不是工作。

这是我一直在运行的代码:

#include <iostream>
#include <fstream>
using namespace std;

int main(){

    ifstream myfile;
    myfile.open("Text.txt");

    if(!myfile.is_open()){
        cout<<"File Not Opened"<<endl;
    }

    myfile.close();

    return 0;
}

这是我的文件夹结构:

enter image description here

任何帮助,将不胜感激

c++ xcode
1个回答
-1
投票

Text.txt必须位于同一文件夹中xcodeproj

如果仍然不工作,只写有std::ofstream一些文件,看看它会被写入。这将是相同的文件夹从中你需要阅读的人。

如果直接从终端启动执行的程序,从启动电流末端目录将决定读取目录。

© www.soinside.com 2019 - 2024. All rights reserved.