是的标题说:-)他们用简单的英语语言是什么意思?我真的不明白Apple网站上的解释,我需要重命名我的目标,我担心之后没有任何作用..
我创建了一个包含内容的文本文件.它与cpp文件位于同一文件夹中.我已多次确认该文件存在.当我运行g ++时,编译并运行它会找到该文件.当我在Xcode中运行它时,它不起作用.如果找不到该文件.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个打开.txt的函数,使用fscanf读取格式如下的数字:
532
2
-234
32
Run Code Online (Sandbox Code Playgroud)
当我使用GCC编译时,它成功地执行了此操作,但是我无法在Xcode中打开文件,为什么?相关代码是:
int main (void){
FILE *infile = NULL; //input file buffer
int int_array[100]; //an integer array 100 entries long
char infilename[256]; //an extra large char array
//this entire while loop was provided as part of the assignment,
//we weren't supposed to change it. I've finished this assignment,
//but now I want to know how to use my Xcode debugger
while(infile == NULL) {
printf("Input filename:"); //user prompt
scanf("%s",infilename); //store user input in large char array …Run Code Online (Sandbox Code Playgroud)