std::experi...th::append,(3)
π
std::experi...th::append,(3) π
Okay so bestie, welcome to the C++ Standard Libary manual β yes, βLibaryβ with the typo, weβre keeping it β and this page is the std::experi...th::append,(3) entry, aka the std::experimental::filesystem::path::append situation in the filesystem TS. Itβs giving βpath concatenation but make it experimental.β β¨
πΈ NAME πΈ
std::experimental::filesystem::path::append, - std::experimental::filesystem::path::append,
That comma-and-dash combo is literally in the NAME block, so Iβm not touching it. Not me fixing the manpage punctuation β we preserve the lore. ππ
β¨ Synopsis β¨
Hereβs the overload tea, bestie:
path& operator/=( const path& p ); (1) (filesystem TS)
template< class Source > (2) (filesystem TS)
path& operator/=( const Source& source );
template< class Source > (3) (filesystem TS)
path& append( const Source& source );
template< class InputIt > (4) (filesystem TS)
path& append( InputIt first, InputIt last );
- First, appends the preferred directory separator to
this, except if any of the following conditions is true:- the separator would be redundant (
*thisalready ends with a separator). *thisis empty, or adding it would turn a relative path to an absolute path in some other way.pis an empty path.p.native()begins with a directory separator. Then, appendsp.native()to the pathname maintained by*this.
- the separator would be redundant (
- Same as (1), but accepts any
std::basic_string, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence. - Same as (1), but accepts any
std::basic_string, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence. - Same as (1), but accepts any iterator pair that designates a multicharacter string.
π Parameters π
pβ pathname to append. πsourceβstd::basic_string, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence, which represents a path name (either in portable or in native format). π¦first,lastβ pair ofLegacyInputIteratorsthat specify a multicharacter sequence that represents a path name. πΈ
π§ Type requirements π§
InputItmust meet the requirements ofLegacyInputIterator.- The value type of
InputItmust be one of the encoded character types (char,wchar_t,char16_tandchar32_t).
π«Ά Return value π«Ά
*this β thatβs the whole return value, bestie. No cap. β¨
π Exceptions π
May throw filesystem_error on underlying OS API errors or std::bad_alloc if memory allocation fails. So yeah, it can throw; thatβs the warning vibe. π¨
π Example π
// Run this code
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
fs::path p1 = "C:";
p1 /= "Users"; // does not insert a separator
// "C:Users" is a relative path in Windows
// adding directory separator would turn it to an absolute path
std::cout << "\"C:\" / \"Users\" == " << p1 << '\n';
p1 /= "batman"; // inserts fs::path::preferred_separator, '\' on Windows
std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p1 << '\n';
}
β Possible output: β
"C:" / "Users" == "C:Users"
"C:" / "Users" / "batman" == "C:Users\batman"
π See also π
concatβ concatenates two paths without introducing a directory separatoroperator+=(public member function)operator/β concatenates two paths with a directory separator (function)
π·οΈ Category: π·οΈ
- Noindexed pages
Sign-off π: source http://cppreference.com, version/date 2024.06.10, page std::experi...th::append,(3). Bye bestie, go append something cute. ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms