I want to utilize CMD console. For example If a.cpp is like below
int main(int argc, char* argv[]) {
for (int i = 0; i < argc; i ) {
cout << "argv : " << argv[i] << endl;
}
string path = "c:\\test";
vector<fs::path> v;
vector<fs::path>::iterator it;
for (auto& entry : fs::recursive_directory_iterator(path))
v.push_back(entry.path());
for (it = v.begin(); it != v.end(); it) {
cout << *it << endl;
}
and if I want to run a.exe by CMD console it can be
C:\users> a.exe
and the result would be
"c:\\test\\test1"
"c:\\test\\test1\\test2"
"c:\\test\\test1\\test2\\lastdir"
"c:\\test\\test1\\test2\\lastdir2"
"c:\\test\\test1_1"
"c:\\test\\test1_1\\test1_txt.txt"
But What if I want to change path by CMD console
For example
C:\users> a.exe c:\\temp
and outputs will be
"c:\\temp\\temp_dir"
"c:\\temp\\temp_dir\\temp.txt"
"c:\\temp\\temp_dir2"
CodePudding user response:
You can do this portably since C 17 using
#include <filesystem>
std::filesystem::current_path(std::filesystem::path(path));