get temp directory

Discussion in 'C++' started by Alberto Bignotti, Feb 28, 2008.

  1. How to get user temporany directory from c++ function?

    example:

    string myTempDir = getTempDir();

    now myTempDir contains 'c:\tmp'

    is there a portable function?
    Alberto Bignotti, Feb 28, 2008
    #1
    1. Advertising

  2. Alberto Bignotti wrote:
    > How to get user temporany directory from c++ function?
    >
    > example:
    >
    > string myTempDir = getTempDir();
    >
    > now myTempDir contains 'c:\tmp'
    >
    > is there a portable function?


    No, there is no portable function because there is no portable
    notion of "user temporary directory". However, you could try
    'getenv("TEMP")' or 'getenv("TMP")'. RTFM about it.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Feb 28, 2008
    #2
    1. Advertising

  3. On Feb 28, 4:00 pm, "Alberto Bignotti" <>
    wrote:
    > How to get user temporany directory from c++ function?
    >
    > example:
    >
    > string myTempDir = getTempDir();
    >
    > now myTempDir contains 'c:\tmp'
    >
    > is there a portable function?


    Alberto,

    As Victor says c++ has no notion of a temporary file directory, but if
    you just want to create a temporary file the the C library's stdio
    header provides the function tmpfile():
    http://www.cplusplus.com/reference/clibrary/cstdio/tmpfile.html

    HTH,
    --rob
    [rob desbois], Feb 28, 2008
    #3
  4. Alberto Bignotti

    James Kanze Guest

    On Feb 28, 5:03 pm, "Victor Bazarov" <> wrote:
    > Alberto Bignotti wrote:
    > > How to get user temporany directory from c++ function?


    > > example:


    > > string myTempDir = getTempDir();


    > > now myTempDir contains 'c:\tmp'


    > > is there a portable function?


    > No, there is no portable function because there is no portable
    > notion of "user temporary directory". However, you could try
    > 'getenv("TEMP")' or 'getenv("TMP")'. RTFM about it.


    TMPDIR is what Posix recommends, I think.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Feb 28, 2008
    #4
    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. Replies:
    2
    Views:
    570
    Mark P
    May 9, 2005
  2. Najd

    Get user Temp directory

    Najd, Apr 13, 2006, in forum: C++
    Replies:
    6
    Views:
    1,157
  3. A. Farber
    Replies:
    3
    Views:
    256
    Ben Morrow
    Mar 3, 2004
  4. Replies:
    1
    Views:
    315
  5. PerlFAQ Server
    Replies:
    0
    Views:
    259
    PerlFAQ Server
    Apr 26, 2011
Loading...

Share This Page