Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 24, 2012, 01:07 PM   #1
VitaliBR
macrumors newbie
 
Join Date: Feb 2012
"Command Line Tool" and Release

I created a program using the "Command Line Tool" in Xcode4, with C++

Code:
#include <iostream>
#include <fstream>

int main (int argc, const char * argv[])
{
    //Creates an instance of ofstream, and opens example.txt
    std::ofstream a_file ( "example.txt" );
    // Outputs to example.txt through a_file
    a_file<<"This text will now be inside of example.txt";
    // Close the file stream explicitly
    a_file.close();
    
    return 0;
}
When I run it by xcode, it works perfectly and generates the txt file in:
/Users/<user>/Library/Developer/Xcode/DerivedData/<projectname>-crivblennrpgzoarxmkowljdzvmv/Build/Products/Debug

But if I try to run the program directly from the folder, the file is not generated txt

Why?

I created the release version too, but does not run properly (does not generate the txt file)
and in the Release folder is created one file <nameproject>.dSYM

what is unix executable file?

Last edited by VitaliBR; Feb 24, 2012 at 01:48 PM.
VitaliBR is offline   0 Reply With Quote
Old Feb 24, 2012, 08:48 PM   #2
VitaliBR
Thread Starter
macrumors newbie
 
Join Date: Feb 2012
I try:
Code:
    char * dir1 = getcwd(NULL, 0);
    strcat(dir1,"/text1.txt");
    printf("%s \n",dir1);
    myfile1.open(dir1, std::ios::binary);

    char * dir2 = getcwd(NULL, 0);
    strcat(dir2,"/text2.txt");
    printf("%s \n",dir2);
    myfile2.open(dir2, std::ios::binary);
in the executable Release show in terminal:
/Users/vitalimateus/text1.txt
/Users/vitalimateus/text2.txt

How do I open the file that it is in the same folder as the executable?
VitaliBR is offline   0 Reply With Quote
Old Feb 25, 2012, 10:29 AM   #3
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
Quote:
Originally Posted by VitaliBR View Post
I try:
Code:
    char * dir1 = getcwd(NULL, 0);
    strcat(dir1,"/text1.txt");
    printf("%s \n",dir1);
    myfile1.open(dir1, std::ios::binary);

    char * dir2 = getcwd(NULL, 0);
    strcat(dir2,"/text2.txt");
    printf("%s \n",dir2);
    myfile2.open(dir2, std::ios::binary);
in the executable Release show in terminal:
/Users/vitalimateus/text1.txt
/Users/vitalimateus/text2.txt

How do I open the file that it is in the same folder as the executable?
If you double-click the executable from the Finder, it should behave as you're expecting it to. If you're running it from the Terminal, it inherits the Terminal's current working directory, which defaults to your home folder.
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
AT&T new line activation and using that phone to cover another line ChubZ iPhone 5 Mar 8, 2011 10:03 PM
Will a MacBook receive 5.1 via optical line in and output 5.1 via optical line out? PhazonUK MacBook 0 Jan 14, 2011 04:57 PM
No sound from line out and a red light in optical line out Ana Mac Pro 3 Aug 4, 2009 04:27 AM
Command Line FTP and Moving Files mms General Mac Discussion 5 Feb 20, 2004 12:28 AM
Review: Apple's Hardware Line Updates and Hints MacRumors MacRumors News Discussion (archive) 27 Mar 30, 2003 06:58 PM


All times are GMT -5. The time now is 04:56 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC