Chapter 4

Building Directories and Contents

In This Chapter

arrow Creating and deleting directories

arrow Getting the contents of a directory

arrow Copying and moving, and why they are related

arrow Moving and renaming files and why they are similar

We’re about to say something you might not believe: C++ provides no functions for creating directories and getting the contents of a directory.

Really! We know it’s hard to believe, but we can make two points about this:

  • There really is a (more-or-less) good reason for this lack: C++ is a general-purpose language: Issues that deal with directories are specific to individual operating systems. Thus it doesn’t make sense to include such features in C++. (Supposedly. So they say. We guess. Whatever.)
  • Some brave rebels have added some functions — and these functions exist in most C++ implementations. Whew! That’s a good thing — otherwise you’d have to call in to the operating system to create or modify a directory.

C++ has a holdover from the C programming language in the header file stdio.h that includes functions for renaming and removing files and directories. ...

Get C++ All-in-One For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.