Access Dynamic path/folder with ios:ofstream

This is a discussion on Access Dynamic path/folder with ios:ofstream within the C++ Programming forums, part of the General Programming Boards category; For Making long description short see my case: Code: suppose, path: "../defult123/test.txt" my code: ofstream fout("../defult123/test.txt",ios::out); Here in "defult123", "default" ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    6

    Question Access Dynamic path/folder with ios:ofstream

    For Making long description short see my case:

    Code:
    suppose,
    
    path: "../defult123/test.txt"
    
    my code: ofstream fout("../defult123/test.txt",ios::out);
    
    Here in "defult123", "default" is static but "123" is dynamic .So Basically 
    
    path should be written as: "../default***/test.txt"
    So how can i access this dynamic path for writing in test.txt file.

    Code:
    so should be working ??
    ofstream fout("../default*/test.txt") 
    
    or,do  i have to list directory fist then check for folder named "default" in sub folder? if so then how do i do that?
    please be a help....

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    If you are literally trying to use bash shell globbing in C++:
    Code:
    ofstream fout("../default*/test.txt")
    You are out of luck. You can only do that in a system() or exec() command.

    In any case, an ofstream is one object referring to one specific file, it cannot be an indeterminate number of different files.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    6
    Quote Originally Posted by MK27 View Post
    If you are literally trying to use bash shell globbing in C++:
    Code:
    ofstream fout("../default*/test.txt")
    You are out of luck. You can only do that in a system() or exec() command.

    In any case, an ofstream is one object referring to one specific file, it cannot be an indeterminate number of different files.
    So what should i do for this problem?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Build the string that represents the filename, using whatever string building tools you like (stringstreams, etc.). Then pass the .c_str() of that string to your ofstream constructor.

    If you're saying "how do I know what the number is on the file that's out there", then you'll probably want to do something system specific.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    6
    FindFirstFile Function is what made my day.Thanks mates.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-23-2009, 01:55 PM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. Replies: 4
    Last Post: 11-02-2006, 11:41 AM
  4. ww hosting and SSH access
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-07-2005, 09:49 AM
  5. using DAO without MS Access installed
    By zMan in forum Windows Programming
    Replies: 2
    Last Post: 02-20-2002, 03:14 PM

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