iTerm C++ and stuff

Discussion in 'Mac Programming' started by dizzled, Feb 28, 2007.

  1. dizzled macrumors newbie

    May 31, 2006
    Hey everyone,
    I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

    Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.
  2. relimw macrumors 6502a

    May 6, 2004
    Without knowing what the program is, this is almost impossible to answer why it would be doing that. You can try using redirection:
    cat sometext.txt > here.txt
    You can us links, it'll get rid of all those multiple directories you have to type to get places, but you still have to cd :)

    ln -s /usr/bin/ mbin
    This would drop a link named mbin in your local directory linked to /usr/bin/
  3. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK

    Is it a C program? If so you can always use absolute paths in the names of your output files or use the function chdir() to change the working directory.

    In Unix you can create soft links to files and directories. To create a soft link in your current directory to another directory or file use:-

    ln -s path-to-the-directory
    ln -s path-to-the-directory some-name-for-the-link
    Do a 'man ln' for full details!

    Anyway once you've create a soft link you can cd to it, list it etc.

    Also, you might find the command line commands pushd and popd helpful.

    b e n

    EDIT: Sorry didn't read relimw's post fully! Excuse the repitition!
    EDIT: Oops, didn't see the C++ in the title!
  4. Eraserhead macrumors G4


    Nov 3, 2005
    I would really use terminal ;), you can also set up aliases by editing the profile folder in your home directory (it's hidden but if it isn't there create one.)

    This is mine:

    # Your previous .profile  (if any) is saved as .profile.dpsaved
    # Setting the path for DarwinPorts.
    export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    test -r /sw/bin/ && . /sw/bin/
    alias cdProg='cd ~/Documents/Programming/'
    alias matlab='/Applications/Matlab_SV701/bin/matlab -nojvm'
    alias sye='cd ~/documents/lecture\ courses/second\ year\ essay'
    alias lc='cd ~/documents/lecture\ courses'
    alias cprog='cd ~/documents/programming/c\ programming/'
    Then I can type cprog in terminal and go to the C programming directory.
  5. dizzled thread starter macrumors newbie

    May 31, 2006

Share This Page