0

The best way to explain my problem is probably just to show you my code, because it's as simple as it gets.

#include <iostream>
#include <fstream>

int main (int argc, const char * argv[])
{

    std::ifstream in;
    std::string line;
    in.open("test.txt");
    if (in.fail()) std::cout << "failed. \n";
    getline(in, line);
    std::cout << line;

    return 0;
}

So when I run this, console is returning "failed." instead of opening up the file called test.txt — which is in the same folder as my .xcodeproj file and is also displayed in my Xcode navigator.

I'm not sure what I'm misunderstanding about this process, but I suspect it will be something simple.

Thanks! :)

1 Answer 1

3

The file is in the same directory as your .xcodeproj file? Well, there's your problem right here.

By default, the working directory of a process launched from Xcode will be the output directory (that is, the directory where the program is). Depending on your Xcode version, it's probably going to be in <Project Directory>/build/Debug.

Try moving the file there.

Sign up to request clarification or add additional context in comments.

2 Comments

Woohoo! This was the solution, thanks! The folder name ended up being: /Users/username/Library/Developer/Xcode/DerivedData/project_dir/Build/Products/Debug
Found a good reference on creating output directories in Xcode 4: stackoverflow.com/questions/4233581/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.