Printing current file name with extension in C++ -
i writing c++ code , want print current filename extension. yes, it's 1 of asked questions. 1 solution use argv[0]. cool, it's not giving extension. can have extension?
you can print full path name using std::cout << __file__
.
if want print file name alone, can do:
std::string file = __file__; size_t index; (index = file.size(); index > 0; index--) { if (file[index - 1] == '\\' || file[index - 1] == '/') break; } std::cout << file.substr(index);
Comments
Post a Comment