BarryK
BarryK

Reputation: 21

using std::filesystem::recursive_directory_iterator; (Console App works, VCL App Doesn't)

I'm wanting to use std::filesystem::recursive_directory_iterator to list files in a folder and subfolder.

This code works fine in a Console Application:

#include <iostream>
#include <vector>
#include <string>
#include <filesystem>

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

int main() {
    string path = "./";

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

    return EXIT_SUCCESS;
}

However, in the VCL App with the following code:

#include <vcl.h>
#pragma hdrstop
#include <fstream.h>
#include <stdio.h>
#include <dir.h>
#include <iostream>
#include <vector>
#include <string>
#include <filesystem>

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

#include "OSSEncryptByList.h"
#include "OSSMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TEncryptByListForm *EncryptByListForm;
//---------------------------------------------------------------------------
__fastcall TEncryptByListForm::TEncryptByListForm(TComponent* Owner)
    : TForm(Owner)
{
} 
//---------------------------------------------------------------------------
void TEncryptByListForm::ShowListForm()
{
    // blah...

The error message is:

[bcc32 Error] OSSEncryptByList.cpp(11): E2209 Unable to open include file 'filesystem'

For some reason, #include <filesystem> is failing in the VCL Application but not in the Console Application.

Upvotes: 0

Views: 144

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597906

Your Console project is configured to use a Clang-based C++ compiler, but your GUI project is configured to use the "classic" Borland C++ compiler instead. The classic compiler does not support C++11, and thus cannot use the <filesystem> library. You will have to go into your Project Options and disable the "Use 'classic' Borland compiler" option in the C++ Compiler settings.

Upvotes: 0

Related Questions