PDA

View Full Version : Input/Output with files in XCode




crisro996
Jul 21, 2012, 10:10 AM
Hi there, I'm trying to learn C++ on Mac or actually learn to use XCode :D

I have managed to get input/output with working, but after giving the full path of the file I was writing in/reading from:
ifstream f("users/.../data.in")

My question is, how can I just give the location as data.in.
ifstream f("data.in") I've been studying C++ on Windows until now and it's really simple in MS VC++, you just put the name of the file and you're good to go.



chown33
Jul 21, 2012, 12:09 PM
I have managed to get input/output with working, but after giving the full path of the file I was writing in/reading from:
ifstream f("users/.../data.in")

That's not a full path, so it won't work. Please post what you actually used.

My question is, how can I just give the location as data.in.
ifstream f("data.in") I've been studying C++ on Windows until now and it's really simple in MS VC++, you just put the name of the file and you're good to go.
You should study what working directory (http://en.wikipedia.org/wiki/Working_directory) and relative path (http://en.wikipedia.org/wiki/Path_(computing)) means.

Then learn how to change your working directory in Xcode (http://forums.macrumors.com/showthread.php?t=1285568).

crisro996
Jul 21, 2012, 12:20 PM
That's not a full path, so it won't work. Please post what you actually used.


You should study what working directory (http://en.wikipedia.org/wiki/Working_directory) and relative path (http://en.wikipedia.org/wiki/Path_(computing)) means.

Then learn how to change your working directory in Xcode (http://forums.macrumors.com/showthread.php?t=1285568).

Thank you, worked perfectly. Thanks for those links as well, very interesting.