Thread: save to temp dir?

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22

    Question save to temp dir?

    Ok i want to save to the temp directory this is wat i have so far

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std; 
    
    int main(){
    
    int test (123);
    string line;
    
    		ifstream omyfile;
    	
    		omyfile.open("C:/Documents and Settings/&#37;USERNAME%/Local Settings/Temp/test.txt");
    		getline (omyfile,line);
    
    		omyfile.close();
    
    	ofstream imyfile;
    
    imyfile.open ("C:/Documents and Settings/%USERNAME%/Local Settings/Temp/test.txt");
    	
    		imyfile << test<<line;
    		imyfile.close();
    
    	return 0;
    
    };
    ok i think problem is somthing to do with %USENAME%
    thx
    Last edited by DDAZZA; 06-10-2007 at 08:05 AM. Reason: updating code

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    In part. You need to interrogate the system for the current user name (look up GetUserName() in the win32 SDK). "..../&#37;USERNAME%/Local Settings/Temp" is also a directory; you need to append a filename to the path.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    630
    Use boost filesystem or do what grumpy said.

  4. #4
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22

    Question

    ok ty

    i found this
    Code:
    HRESULT GetUserName(
        BSTR *pbstrUserName
    );
    but im not really sure how i use it
    plz can som1 explain it for me, sorry

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    GetUserName() in the win32 SDK has two arguments (a pointer to a buffer that will receive the username, and the length of that buffer) and returns a BOOL (zero for failure, non-zero for success). You are presumably using some other library.

    The username needs to be substituted in where you have &#37;USERNAME%, and (for example) a filename named file.dat needs to be appended on the end of the path (so if the user is "grumpy", the filename will look like "C:/Documents and Settings/grumpy/Local Settings/Temp/filename.dat"

  6. #6
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    ok


    when compiling i get the following error
    error C3861: 'GetUserName': identifier not found

    is this because i havnt got
    #include <windows.h>

    if i add that
    i get this error
    fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

    is this because im using the visual C++ express edition ?

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Could be; I've never used the express edition, so don't know its shortcomings relative to the flagship products.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You may need to specifically specify the include path which contains <windows.h>. I don't know how to do this with Microsoft compilers. On the other hand, maybe that compiler doesn't even have those functions.

    You could always try a different compiler.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

    is this because im using the visual C++ express edition ?
    Yes - You need to instal Windows SDK and add paths of SDK include, library and executable directories to your IDE settings -
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    ok ty i will look into getting a diffrent complier

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> ok ty i will look into getting a diffrent complier

    Why? Just finish installing the VC++ Express. Part of the installation process is to download the SDK separately.

  12. #12
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    because im asuming that with other compliers you will be also allowed to make win32 applications

    with this i can only make win32 console applications and windows forms applications

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    No, you can also make Win32 windows applications without forms.

  14. #14
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    ? do you mean WIN32 console applications,
    i know you can make them

    there is no WYSIWYG is there?

  15. #15
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I think you're looking for a resource editor, which VC++ has. I'm not sure about express, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. Problem Putting INTs Into a CHAR Array
    By cram in forum C++ Programming
    Replies: 13
    Last Post: 10-13-2004, 07:53 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Help with my c-program
    By duty11694 in forum C Programming
    Replies: 1
    Last Post: 11-15-2002, 02:13 PM