I'm using Visual Studio 2019. The file path must be taken as an User input. I'm new to C++ and will appreciate any help i can get.
#include <iostream>
#include <string>
int main()
{
std::string filename;
std::cout << "Enter file path: ";
std::cin >> filename; // "Example: C:/test/file1.txt"
// Remove directory if present.
// Do this before extension removal incase directory has a period character.
const size_t last_slash_idx = filename.find_last_of("\\/");
if (std::string::npos != last_slash_idx)
{
filename.erase(0, last_slash_idx + 1);
}
std::cout << filename;
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.