Namespaces
Variants

std::experimental::filesystem:: read_symlink

From cppreference.net
Definiert im Header <experimental/filesystem>
path read_symlink ( const path & p ) ;
path read_symlink ( const path & p, error_code & ec ) ;
(Filesystem TS)

Wenn der Pfad p auf einen symbolischen Link verweist, gibt ein neues Pfadobjekt zurück, das auf das Ziel dieses symbolischen Links verweist.

Es ist ein Fehler, wenn p nicht auf einen symbolischen Link verweist.

Die nicht-werfende Überladung gibt bei Fehlern einen leeren Pfad zurück.

Inhaltsverzeichnis

Parameter

p - Pfad zu einem Symlink
ec - Out-Parameter für Fehlerberichterstattung in der nicht-werfenden Überladung

Rückgabewert

Das Ziel des Symlinks (das möglicherweise nicht existieren muss).

Ausnahmen

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 and the OS error code as the error code argument. std:: bad_alloc 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 has
noexcept Spezifikation:
noexcept

Beispiel

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    // on a typical Linux system, /lib/libc.so.6 is a symlink
    fs::path p = "/lib/libc.so.6";
    if (exists(p) && is_symlink(p))
        std::cout << p << " -> " << read_symlink(p) << '\n';
    else
        std::cout << p << " does not exist or is not a symlink\n";
}

Mögliche Ausgabe:

"/lib/libc.so.6" -> "libc-2.12.so"

Siehe auch

prüft, ob das Argument auf einen symbolischen Link verweist
(Funktion)
erstellt einen symbolischen Link
(Funktion)
kopiert einen symbolischen Link
(Funktion)
bestimmt Dateiattribute
bestimmt Dateiattribute unter Überprüfung des Symlink-Ziels
(Funktion)