C++, Mac, Code Runner, File Read/Write, Newbie

In this forum members can discuss topics about specific programming languages.
Post Reply
gjhugghins
Posts: 2
Joined: Fri Nov 29, 2013 8:28 pm

C++, Mac, Code Runner, File Read/Write, Newbie

Post by gjhugghins »

I'm am just learning C++. I have been solving PE problems to help develop my skills. I am working on Problem 22. I have been somewhat successful in reading and writing files, but I have a question.

The normal Windows/PC type pathname, C:\folder1\folder2\filename.txt, does not appear to work on the Mac. I've been using Mac for a long time, but don't know the proper way to designate the path so that C++ will go to the file. Can someone teach me, or point me to an appropriate resource?

Thanks for your help.

gjhugghins
User avatar
jaap
Posts: 587
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: C++, Mac, Code Runner, File Read/Write, Newbie

Post by jaap »

Have you tried using forward slashes (/) instead of backslashes (\) ?

Backslashes are very Windows-specific, and are generally used as an escape character on other systems (e.g. \t is converted to a tab character).
User avatar
nicolas.patrois
Posts: 118
Joined: Fri Jul 26, 2013 4:54 pm
Contact:

Re: C++, Mac, Code Runner, File Read/Write, Newbie

Post by nicolas.patrois »

Does Windows understand now the universal /?
If your language is OS-friendly, it should have a specific option for the directory delimiter.
Image
gjhugghins
Posts: 2
Joined: Fri Nov 29, 2013 8:28 pm

Re: C++, Mac, Code Runner, File Read/Write, Newbie

Post by gjhugghins »

I got some help from a friend. The key for me was this: "For the Mac you use something like the following: /Users/gjhugghins/Documents/C++ Programming/WorkOnNext/newnames.txt. Where / is the root of the drive." There is no drive letter AND the slashes are forward.

Some additional details can be found, below.

The Mac OS is a derivative of the AT&T (Bell Labs) Unix Operating system. See: http://en.wikipedia.org/wiki/Unix

The file structure is considerably different than the MS-DOS but each use a hierarchical structure to represent the branches of a tree and the files the leafs.

For the Mac you should see something like the following: /usr/rboydstun/documents/programs. Where / is the root of the drive. See: http://en.wikipedia.org/wiki/Unix_direc ... ory_layout

If you open the console then you should be able to navigate the file system without the aid of the finder application.

You should research the command available for the shell being used: Bash http://en.wikipedia.org/wiki/Bash_shell
Post Reply