Creating files in specific directories

This is a discussion on Creating files in specific directories within the C++ Programming forums, part of the General Programming Boards category; I can write information to files, but I want to be able to save the resulting file to various folders. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Unhappy Creating files in specific directories

    I can write information to files, but I want to be able to save the resulting file to various folders. How do I do this? An example of my code is below. Thanks in advance for any help!

    -----------------------
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>

    int main()
    {
    string Name,
    School;

    ofstream a_file("Info.doc");
    a_file<< "Your name is : " << Name <<endl;
    a_file<< "You go to " << School <<endl;
    a_file.close();

    return(0);
    }
    -----------------------

    I would like to be able to save Info.doc (or whatever my file name is) in a different folder, anything but the base folder that I ran the program from (where the file normally creates). Any help is appreciated.

    Kyoto Oshiro
    http://www.angelfire.com/realm2/horizon/files.html
    Horizon Games

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,674
    Code:
    ofstream a_file("C:\\NameOf\\Other\\Folder\\Info.doc");
    Of course, make sure the the folder/directory you are going to create the file in first exists. Otherwise you will need to go through some steps to create it (the directory) in your program.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Smile Thanks a lot

    Oh, alright then. Sounds easy enough. Thanks for the help!


    Kyoto Oshiro
    http://www.angelfire.com/realm2/horizon/files.html
    Horizon Games

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Directories and files using dirent.h
    By totalnewbie in forum C Programming
    Replies: 6
    Last Post: 11-19-2008, 04:10 PM
  2. creating directories
    By hiya in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2005, 12:08 AM
  3. creating .DAT files
    By breed in forum C Programming
    Replies: 3
    Last Post: 11-30-2001, 08:09 AM
  4. Creating a prog to edit files with certin extention
    By destroyer32428 in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2001, 02:08 AM
  5. creating make files
    By Unregistered in forum Linux Programming
    Replies: 4
    Last Post: 09-22-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21