getcwd changes? how can I get current path?

Discussion in 'C++' started by Jona, May 23, 2007.

  1. Jona

    Jona Guest

    Issue:
    *Get the path location of my executable.

    Semi Fix..
    *Using getcwd() or plainly giving no path would also do the job...
    say reading a file...

    *The problem is when I call other functions like...
    CreateDirectory("foo",NULL)
    it changes my default directory to \foo folder...
    so when I call getcwd() or simply don't give a path to access a file,
    now the default folder is foo ....
    Any Idea why this happens? how can it be defaulted back to its
    original path?

    is there a better way to do this?

    thanks,
    Jonathan
     
    Jona, May 23, 2007
    #1
    1. Advertising

  2. Jona

    Jack Klein Guest

    On 23 May 2007 13:51:52 -0700, Jona <> wrote
    in comp.lang.c++:

    > Issue:
    > *Get the path location of my executable.


    The standard C++ language does not define the operation of file
    systems, because different operating systems implement them very
    differently. So the C++ language has no concept of path, nor any
    functions that deal with it.

    The first string in the second argument to main, conventionally called
    argv[0], might contain the full path of your executable, depending on
    your operating system, or it might not.

    > Semi Fix..
    > *Using getcwd() or plainly giving no path would also do the job...
    > say reading a file...


    There is no function "getcwd()" in the standard C++ library. If your
    platform provides such a function, it is an extension and your
    compiler and platform define it, not the C++ language.

    > *The problem is when I call other functions like...
    > CreateDirectory("foo",NULL)
    > it changes my default directory to \foo folder...
    > so when I call getcwd() or simply don't give a path to access a file,
    > now the default folder is foo ....
    > Any Idea why this happens? how can it be defaulted back to its
    > original path?
    >
    > is there a better way to do this?


    You need to ask in a platform specific newsgroup. In your case,
    news:comp.os.ms-windows.programmer.win32 is a good one.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, May 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erik  Bethke
    Replies:
    7
    Views:
    387
    =?ISO-8859-1?Q?Walter_D=F6rwald?=
    Feb 9, 2005
  2. r0g
    Replies:
    3
    Views:
    430
  3. Replies:
    2
    Views:
    504
  4. amos
    Replies:
    1
    Views:
    297
    Eric Hodel
    Jan 22, 2007
  5. Addy

    Win32 getcwd() and cygdrive

    Addy, Aug 3, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    420
    Darren Dunham
    Aug 3, 2005
Loading...

Share This Page