Results 1 to 3 of 3
  1. #1
    Ccode C++ input file

    Member Since
    Nov 12, 2009
    Posts
    1
    Ccode C++ input file
    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[]) {
    //Declarations
    float a;
    float b;
    float c;

    // Input
    ifstream inData;
    inData.open("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.
    logout

    [Process completed]


    Question
    Why is this not working?

  2. #2
    Ccode C++ input file

    Member Since
    May 02, 2009
    Posts
    480
    Specs:
    MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB
    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:

    inData.open("/Users/blah/data.dat");

  3. #3
    Ccode C++ input file
    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,188
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3
    Is the file data.dat located in the same directory as the executable? A "ls" in that directory will clear that up..

    Regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vip file, hmo file hmp file
    By stuartavfc72 in forum Music, Audio, and Podcasting
    Replies: 4
    Last Post: 10-26-2013, 12:47 AM
  2. Mp3 file(s) instead of microphone input on OS X?
    By nsay in forum Music, Audio, and Podcasting
    Replies: 0
    Last Post: 07-02-2009, 07:45 AM
  3. "linker input file unsed because linking not done",ABINIT
    By min4 in forum Running Windows (or anything else) on your Mac
    Replies: 0
    Last Post: 10-07-2008, 05:54 AM
  4. AV input?
    By Immune Heart in forum Other Hardware and Peripherals
    Replies: 4
    Last Post: 04-28-2008, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •