New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Ccode C++ input file

Post Reply New Thread Subscribe

Thread Tools

Member Since: Nov 12, 2009
Posts: 1
noll is on a distinguished road

noll is offline
Question why is this not working?

// Input
// Noll Roberts 2009-11-12
#include <iostream> // endl cout
#include <iomanip> // setw
#include <fstream> //
#include <string> // string variables
using namespace std;

int main (int argc, char * const argv[]) {
float a;
float b;
float c;

// Input
ifstream inData;"data.dat");
if (!inData)
cout << "Can't open input file." << endl;
return 1;

inData >> a;
inData >> b;
inData >> c;

return 0;

data file
19.5 18.7 19

I added the data file to my Xcode project

error message
/Users/nollroberts/Xcode/indata/build/Release/indata ; exit;
noll-roberts-imac-2:~ nollroberts$ /Users/nollroberts/Xcode/indata/build/Release/indata ; exit;
Can't open input file.

[Process completed]

Why is this not working?
QUOTE Thanks

Member Since: May 02, 2009
Posts: 480
wmprice1240 has a spectacular aura about
Mac Specs: MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB

wmprice1240 is offline
Hi, welcome to the forums.

Where does 'data.dat' live? I was able to compile and run your code, however, you need to give an absolute path for your data file. Something like:"/Users/blah/data.dat");
QUOTE Thanks

Raz0rEdge's Avatar
Member Since: Jul 17, 2009
Location: MA
Posts: 8,133
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
Is the file data.dat located in the same directory as the executable? A "ls" in that directory will clear that up..

QUOTE Thanks

Post Reply New Thread Subscribe

« Perl/Tk for OS X? | php can't connect to mysql »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Moving mp3's to your Audiobooks folder bobtomay iPod Hardware and Accessories 10 10-10-2009 12:02 PM
iTunes Tips And Tricks RJgamer iPod Hardware and Accessories 2 07-12-2007 11:59 AM
ZFS To Become Default File System In Leopard kaidomac Apple Rumors and Reports 21 06-26-2007 02:29 PM
Always Losing Input Menu Preferences fumomo OS X - Operating System 3 05-13-2004 07:32 AM

All times are GMT -4. The time now is 12:14 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?