I am trying to open a file and print the contents of the file to the terminal window. It works when I put the file right in the directory with the Solution but not if the file is out on my desktop and I use the full path. Any ideas what I am doing wrong? Here is the code:
Thanks for the reply. I've added the file to the C Drive folder and tried "C:\\sample.csv" and "C://sample.csv" and neither worked. It still continues to work from the local directory. Very strange. I am not getting any compile errors, I am just getting the else message that I've asked for in the event that the file is not successfully opened which is "Could not open file."
Ugh. Does fstream set errno? You could print it out to see why it's failing. Looking at the reference, I don't see that open() provides any details on why it might fail.
Are the file permissions read-only? I bet that would do it. If you're just reading the file, use ifstream instead of fstream, which supports both reading and writing.