In the example code below auto was used I want to know the type to replace auto in this code. typeid gave me this: "NSt10filesystem7__cxx1115directory_entryE".
And gdb told me this: "const std::filesystem::__cxx11::directory_entry &"
So I assumed "auto" could be replace with "std::filesystem::directory_entry", but I was wrong.
I don't just want to know the type but a reasonable method for determining the type.
typeid gave me this: "NSt10filesystem7__cxx1115directory_entryE".
Actually your code, even adding the missing parentheses, does not compile:
main.cpp:
1 2 3 4 5 6 7 8 9 10 11
#include <filesystem>
#include <iostream>
#include <typeinfo>
int main()
{
for (auto& dit : std::filesystem::directory_iterator(".")) {
std::cout << typeid(dit.name()) << '\n';
}
}
Output:
main.cpp: In function 'int main()':
main.cpp:9:33: error: 'const class std::filesystem::__cxx11::directory_entry' has no member named 'name'
9 | std::cout << typeid(dit.name()) << '\n';
| ^~~~
Assuming you meant:
1 2 3 4 5 6 7 8 9 10 11
#include <filesystem>
#include <iostream>
#include <typeinfo>
int main()
{
for (auto& dit : std::filesystem::directory_iterator(".")) {
std::cout << typeid(dit).name() << '\n';
}
}
- - -
To be honest, wilson52, and this isn’t a rant, I think your worst mistake was not providing a compilable code.
There’re people here who answer several times every day, and I think they’re sick and tired of correcting the codes just to get the compiler directions, so they sometimes neglect some post.
If you fancy fast and canny answers, take your time to ask good questions.
Just a suggestion :)
No, you can tell from his response that that is not the case.
Some people just have this weird "leave no trace" mindset after a question has been answered.