Autor Beitrag
Experience1986
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 192

Win XP Pro SP2
Delphi 7
BeitragVerfasst: Mi 06.09.06 10:45 
Hi,

ich suche eine Methode die mir aus einem Dateipfad den Dateinamen extrahiert. Ich bin leider totaler C++ Anfänger, ich hoffe ihr könnt wie immer kompentent Hilfe leisten.


Danke schon mal im voraus.


Moderiert von user profile iconUGrohne: Topic aus C# - Die Sprache verschoben am Mi 06.09.2006 um 12:24
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mi 06.09.06 11:34 
ausblenden Quelltext
1:
2:
3:
4:
5:
    std::string str = "/path/to/filename.ext";
    size_t pos = str.find_last_of("/");
    std::string filename = str.substr(pos + 1);

    std::cout << filename << std::endl;
Entsprechend mit 'nem Backslash (das Escapen nicht vergessen, als "\\"), wenn es für Windows sein soll.

Edit:
An den Pfad gelangt man mit str.substr(0, pos).

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert