Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For creating a directory you can use the C function:</p> <pre><code>int mkdir(const char *pathname, mode_t mode); </code></pre> <p>If you can use <a href="http://www.boost.org/" rel="nofollow">Boost</a>, then it really becomes easier and more C++ friendly:</p> <pre><code>bool create_directories(const path&amp; p); // usage example boost::filesystem::create_directories("./BobtheBuilder"); </code></pre> <p>As you mention in your question , you can use both absolute and relative paths. It just depends on what is your intention. In your case, you could just do:</p> <pre><code>boost::filesystem::create_directories("./BobtheBuilder"); ofstream out("./BobtheBuilder/NewFile.txt"); </code></pre> <p>not needing to specify the absolute path at all.</p> <p>If you often need to manage paths, Boost provides many useful tools for path management. Just as an example, consider the problem you mention in your question: you want to get the full path to the current directory and then append a relative path. You could do this very easily:</p> <pre><code> #include &lt;boost/filesystem.hpp&gt; namespace fs = boost::filesystem; ... fs::path curr_abs_path = fs::current_path(); fs::path rel_path = "foo/bar"; fs::path combined = (curr_abs_path /= rel_path); cout &lt;&lt; combined &lt;&lt; endl; </code></pre> <p>Assuming the current directory is /tmp/ the previous code snippet would print:</p> <blockquote> <p>/tmp/foo/bar</p> </blockquote> <p><code>operator/=</code> is responsible for appending two paths and returning the combined result.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload