Thread: How do I specify a directory with ifstream and ofstream?

  1. #16
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by laserlight View Post
    Yes, but not with the standard library. You could consider the use of Boost.Filesystem.
    Where do I download this library?

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It's part of the boost library available at the same site that hosts that doc page.

  3. #18
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Daved View Post
    It's part of the boost library available at the same site that hosts that doc page.
    Ahh...ok. Thanks. I guess I was expecting to see a link to download it at the part of the site I was viewing.

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Streams are designed for what their name implies - streams. Just b/c it is a file stream does not mean it can navigate folder structures. That is normally up to the operating system. The C standard library as well as the Win32 API provide plenty of functionality for all of that.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Bubba
    Streams are designed for what their name implies - streams. Just b/c it is a file stream does not mean it can navigate folder structures. That is normally up to the operating system.
    If by "navigate folder structures" you mean access files that are outside the current directory, then I believe that it can, but the path name format is implementation defined, which in this case means operating system dependent. This is why I suggested the use of Boost.Filesystem as it provides a generally portable solution.

    Quote Originally Posted by Bubba
    The C standard library as well as the Win32 API provide plenty of functionality for all of that.
    I do not think that the C standard library has any advantage over the C++ I/O streams in this respect. The respective functions are also concerned about file names, not directory names or path names in general.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Yes but you have such things as setcwd and getcwd and so forth that do interact with the file system. Just b/c you can specify a path for ifstream and ofstream does not mean they should be used for folder navigation.

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Bubba
    Yes but you have such things as setcwd and getcwd and so forth that do interact with the file system.
    setcwd and getcwd are not part of the C standard library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ofstream... broke as a result of ifstream fix
    By tms43 in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2006, 11:40 AM
  2. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 08:34 AM
  3. ofstream, ifstream?
    By Kavity in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2003, 09:49 PM
  4. Replies: 9
    Last Post: 06-06-2002, 07:03 PM
  5. STL to: Cin, Cout, ifstream & ofstream
    By kuphryn in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2001, 09:32 AM