How to open a file and verify its open.

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
Do you launch your program from C:\ folder?
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?
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
Is the working directory wherever the Users directory is? Usualy the working directory is where the executable is located.
You forgot the drive letter.
"Users/Adam/Documents/MoviesCP.txt"" should be something like:
"C:/Users/Adam/Documents/MoviesCP.txt"
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.