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