More newbie questions - file and directory

This is a discussion on More newbie questions - file and directory within the C++ Programming forums, part of the General Programming Boards category; Hi! I would like to know if it is possible for me to create a subdirectory and write to it? ...

  1. #1
    Sunzoner
    Guest

    More newbie questions - file and directory

    Hi!
    I would like to know if it is possible for me to create a subdirectory and write to it?
    For example,
    instead of ...
    b_file.open("1.txt", ios::nocreate);

    Do I do this?
    b_file.open("\txt\1.txt", ios::nocreate);

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Theres dir.h (dos.h also) which have functions like rmdir(), mkdir() in it.

    then there is the system() also

    >>b_file.open("\txt\1.txt", ios::nocreate);

    i dont think "that" is possible, maybe if you try with the whole path then it could be but i wouldn't count on it

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: More newbie questions - file and directory

    Originally posted by Sunzoner
    b_file.open("\txt\1.txt", ios::nocreate);
    The backslash character is a special character used for escape sequences (\t, \n).
    If you want a backslash in your string you need to put an extra backslash before it:
    Code:
    b_file.open("C:\\txt\\1.txt", ios::nocreate);

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    6
    You could always try...
    Code:
    #include <windows.h>
    ..
    	CreateDirectory("txt",NULL);
    	SetCurrentDirectory("txt");
    	b_file.open("1.txt", ios::nocreate);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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