std::experimental::filesystem:: canonical
|
Défini dans l'en-tête
<experimental/filesystem>
|
||
|
path canonical
(
const
path
&
p,
const
path
&
base
=
current_path
(
)
)
;
|
(1) | (filesystem TS) |
|
path canonical
(
const
path
&
p, error_code
&
ec
)
;
|
(2) | (filesystem TS) |
|
path canonical
(
const
path
&
p,
const
path
&
base, error_code
&
ec
)
;
|
(3) | (filesystem TS) |
Convertit le chemin p en un chemin absolu canonique, c'est-à-dire un chemin absolu qui ne contient aucun élément point, point-point ou lien symbolique.
Si p n'est pas un chemin absolu, la fonction se comporte comme s'il était d'abord rendu absolu par absolute ( p, base ) ou absolute ( p ) pour (2) .
Le chemin p doit exister.
Table des matières |
Paramètres
| p | - | un chemin qui peut être absolu ou relatif à base , et qui doit être un chemin existant |
| base | - | chemin de base à utiliser dans le cas où p est relatif |
| ec | - | code d'erreur pour stocker le statut d'erreur |
Valeur de retour
Un chemin absolu qui résout vers le même fichier que absolute ( p, base ) (ou absolute ( p ) pour (2) ).
Exceptions
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument, base as the second argument, and the OS error code as the error code argument. std:: bad_alloc *Note: Le texte à traduire ne contient que des balises HTML et des termes C++ (`std::bad_alloc`), qui ne doivent pas être traduits selon les consignes. Aucun contenu textuel traduisible n'est présent dans cet extrait.* may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload hasCette fonction est modelée d'après la fonction POSIX realpath .
Exemple
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p = fs::path("..") / ".." / "AppData"; std::cout << "Current path is " << fs::current_path() << '\n' << "Canonical path for " << p << " is " << fs::canonical(p) << '\n'; }
Sortie possible :
Current path is "C:\Users\abcdef\AppData\Local\Temp" Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"
Voir aussi
|
représente un chemin
(classe) |
|
|
compose un chemin absolu
convertit un chemin en chemin absolu en reproduisant le comportement spécifique au système d'exploitation (fonction) |