Thread: Need Help With Naming Output Files!!!

  1. #1

    Exclamation Need Help With Naming Output Files!!!

    I am writing a file to ask the user to input the name of the file that they want the data to be stored to. For example ...


    I need to use a cout to ask what the file name they want to use is.... but i dont want to make them type in the entire path.. just the "sample" and make it already add the a:\\ and the .txt Is this possible? If so, how do i do it?

    Any help would be greatly appreciated.


  2. #2
    Registered User cody's Avatar
    Join Date
    Sep 2001

    Yes, of course it's possible You'll need the basic string functions like strlen(), strcpy() or strcat(). (Have a look what the are doin')

    By using these functions you should be able to read in the name for the file and create a string, that will contain the complete path plus the filename.

    Some hints without code:

    1) read filename
    2) lenght of filename?
    3) create empty string with size =

    4 + ("a:\\") + lenght (filename) + 4 (".txt") + 1 "\0"

    4) append the "a:\\"
    5) append the filename
    6) append the ".txt"
    7) append the termination character "\0"

    #include "reallife.h"

  3. #3
    Registered User
    Join Date
    Oct 2001
    Or use function sprintf().

    char name[81], filename[81];

    cout << "Enter filename:";
    cin >> name;
    cout << "filename:" << filename << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Input and Output files
    By matrixhelp in forum C Programming
    Replies: 1
    Last Post: 03-10-2008, 02:07 AM
  3. Replies: 5
    Last Post: 02-25-2008, 06:35 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM