How to open a file and verify its open.

Oct 8, 2014 at 11:15pm
I never see "file open"

What am I doing wrong? Using Xcode 6.0.1

Thanks

1
2
3
4
5
6
7
  fstream nameFile("Users/Adam/Documents/MoviesCP.txt");
    
    if (nameFile.is_open())
    {
        cout << "File open";
    }
Last edited on Oct 8, 2014 at 11:21pm
Oct 8, 2014 at 11:17pm
Do you launch your program from C:\ folder?
Oct 8, 2014 at 11:18pm
Are you sure the file is being successfully opened? Your path seems to suggest you are expecting the working directory to be in the drive root; have you confirmed this is the case?
Oct 8, 2014 at 11:22pm
Its on a mac using Xcode 6.0.1

@Zhuge i don't think its opening at all because it is not outputting "file open"
Last edited on Oct 8, 2014 at 11:23pm
Oct 8, 2014 at 11:28pm
Is the working directory wherever the Users directory is? Usualy the working directory is where the executable is located.
Oct 9, 2014 at 4:24am
You forgot the drive letter.
"Users/Adam/Documents/MoviesCP.txt"" should be something like:
"C:/Users/Adam/Documents/MoviesCP.txt"
Oct 9, 2014 at 4:44am
TC is on a Mac (despite the interesting directory layout), so I don't think drive letters apply. Relative paths are also valid, so I would not assume TC meant to use a absolute path.
Topic archived. No new replies allowed.