0

Where should I store the file that I want to read. I'm using xcode (on a mac) and doing c++.

the code for one of my functions follows - I'm always getting file not found

iFile.open(inputFile);

if (!iFile.good())
{
    cout << "file not found";
}
while (getline ( iFile, line))
{
    oFile << line;
}

iFile.close();
tshepang
  • 12,111
  • 21
  • 91
  • 136
user3316874
  • 223
  • 2
  • 6
  • 10
  • Well, what does `inputFile` contain? – Carey Gregory Sep 12 '14 at 23:26
  • its a .txt file with the following content: – user3316874 Sep 12 '14 at 23:26
  • That wasn't my question. What does the variable `inputFile` contain? For all we know it's random garbage. – Carey Gregory Sep 12 '14 at 23:27
  • cout << "What is the input filename"; cin >> f.inputFile; – user3316874 Sep 12 '14 at 23:28
  • I ask the use for the input file – user3316874 Sep 12 '14 at 23:28
  • And what is `iFile`? Your question has serious problems. First, it doesn't show any of the code we would need to see to guess what the problem is. Second, your question is unclear. What do you mean by where should you store the file? Where on disk? Where in memory? You need to clean up these problems or the question's probably going to be closed. – Carey Gregory Sep 12 '14 at 23:31
  • 1
    Are you sure that the place you are executing the program from and the file are in the same folder? Are you giving the proper relative path? Come on guy, you can do it better for sure, we are not magicians. – Javi Sep 12 '14 at 23:33
  • ifile is an ifstream variable as such: ifstream iFile;. I'm asking where on my disk i – user3316874 Sep 12 '14 at 23:33
  • Where to store your file on disk is far too broad to answer. The most obvious answer would be "wherever you like." – Carey Gregory Sep 12 '14 at 23:35
  • I tried changing iFile.open(inputFile) to iFile.open(prot.txt). The file is still not found – user3316874 Sep 12 '14 at 23:37
  • 1
    [**Read this**](http://stackoverflow.com/questions/14476655/code-runs-perfect-in-g-but-not-in-xcode-cannot-find-file). I'm pretty sure the selected answer is what you're after. – WhozCraig Sep 12 '14 at 23:41

0 Answers0