Use find_last_of
and substr
for that task:
std::string filename = "file.cpp";
std::string extension = "";
// find the last occurrence of '.'
size_t pos = filename.find_last_of(".");
// make sure the poisition is valid
if (pos != string::npos)
extension = filename.substr(pos+1);
else
std::cout << "Coud not find . in the string\n";
This should give you cpp
as an answer.