Answers for "how to get name of file from folder in c++"

C++
3

c++ get files in directory

#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main() {
    std::string path = "/path/to/directory";
    for (const auto & entry : fs::directory_iterator(path))
        std::cout << entry.path() << std::endl;
}
Posted by: Guest on August-15-2020
2

c++ get filename from path

// get filename
std::string base_filename = full_path.substr(full_path.find_last_of("/\") + 1);

// remove extension from filename
std::string::size_type const p(base_filename.find_last_of('.'));
std::string file_without_extension = base_filename.substr(0, p);
Posted by: Guest on April-15-2021

Code answers related to "how to get name of file from folder in c++"

Browse Popular Code Answers by Language