[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppGetExtension
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppGetExtension
(C++) How do I get a filename's extension?
std::string getExtension(const std::string& fileName) { const int length = fileName.length(); for (int i=0; i!=length; ++i) { if (fileName[i]=='.') { return fileName.substr(i+1,length); } } return fileName; } int main() { assert(getExtension("Test.txt")=="txt"); }
- include <string>
- include <cassert>
Other code snippets
Links to topics
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
