recursive_directory_iterator filesystem

closed account (GTXEhUp4)
Hello i have issue and i can't doing and i am gonna getting crazy about that.
I always taking same problem with VS Code and Microsoft Visual Studio. I checked many forums and lots of websites but nothing work ...

I am trying to find extensions files with giving path but any code doesn't becasue of filesystem libary or class (i don't know what is )


Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "recursive_directory_iterator" is undefined autosvn C:\Users\BATUHAN\source\repos\AUTOSVNProject\autosvn\autosvn\autosvn.cpp 15


#include <iostream>
#include <vector>
#include <string>
#include <filesystem>
using namespace std::filesystem::recursive_directory_iterator;

using std::cout; using std::cin;
using std::endl; using std::string;
using std::filesystem::recursive_directory_iterator;
using namespace std;

int main() {
string path = "C:\\Users\\BATUHAN\\Desktop\\A";

for (const auto& file : recursive_directory_iterator(path))
cout << file.path() << endl;

return EXIT_SUCCESS;
}
Last edited on
Try this. This issue is with the filesystem namespace:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <filesystem>

namespace fs = std::filesystem;

using std::cout;
using std::string;

int main() {
	const string path { "C:\\Users\\BATUHAN\\Desktop\\A" };

	for (const auto& file : fs::recursive_directory_iterator(path))
		cout << file.path() << '\n';
}

Last edited on
closed account (GTXEhUp4)
deneme.cpp:5:21: error: 'filesystem' is not a namespace-name
namespace fs = std::filesystem;
^~~~~~~~~~
deneme.cpp:5:31: error: expected namespace-name before ';' token
namespace fs = std::filesystem;
^
deneme.cpp: In function 'int main()':
deneme.cpp:13:26: error: 'fs' has not been declared
for (const auto& file : fs::recursive_directory_iterator(path))
^~
again same issue unfortunately
You will need to (quite forcefully) insist that your compiler uses at least C++17:
cl /std:c++17 /EHsc test.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <filesystem>

using std::cout;
using std::string;
using std::filesystem::recursive_directory_iterator;

int main()
{
   string path = "\\Users";

   for ( const auto& file : recursive_directory_iterator( path ) )
      cout << file.path() << '\n';
}
Last edited on
@baduymus - what version of VS are you using? You need at least VS2019. VS2022 is the current version.

For VS, Project/properties/general/C++ language standard should be at least ISO C++20 (ISO C++17 if you really want, but C++20 is the latest standard).

If you have both VS Code and VS, then IMO VS is the preferred as it is an IDE with editor, compiler, debugger etc all in-built.


Last edited on
closed account (GTXEhUp4)
it's the last version VS2022 and i don't understand why it's happening
baduymus wrote:
it's the last version VS2022

VS 2019/2022/ defaults to C++14 when creating a new project/solution, you have to manually change the project's properties to use C++17/C++20/C++latest.

I recommend you purposely modify the default for new projects using the Property Manager when you have a project open. It isn't just for adding library directories, it can change the language standard and a lot more.

http://www.cplusplus.com/forum/lounge/271176/#msg1169093

Even if you don't use any C++17/20 or later language features compiling with newer than the default C++14 won't make much of a difference.
Oh, and you really should
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
it's the last version VS2022 and i don't understand why it's happening


So have you set the C++ language standard as per my previous post?
seeplus, I suspect the OP has moved on to another topic, this time mucking around with structs.

http://www.cplusplus.com/forum/beginner/283672/
Topic archived. No new replies allowed.