I'm new to C++ so forgive me. I use CodeBlocks which i just installed last week. I need to iterate through every text file in a directory. I found this example online:
#include <filesystem>
for ( const auto &dirEntry : std::filesystem::directory_iterator("saved_decks"))
myHelpFxns::growLogOutputLines("file=" + dirEntry, this->log_output);
Where I'm trying to loop through every text file in the "saved_decks" directory then log the file name.
When I run this, I get the message "error: std::filesystem has not been declared". As per suggestions, I went into CodeBlocks Compiler options and checked the box under compiler flags:
"Have g++ follow the c++ 17 ISO C++ language standard"
Now i changed my only lines of code pertaining to fileystem:
At top of .cpp file:
#include <filesystem>
Inside a method of the class defined in the .cpp file, just to see if it works:
std::filesystem::create_directories("/sandbox/a/b");
And i rebuilt my wxWidgets project. Now I'm getting the error from the builder:
C:\Program Files\CodeBlocks\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\bits\fs_path.h|237|error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')|
And when I try to build the program, it opens the file fs_path.h and shows error on the line:
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__p.is_absolute()
|| (__p.has_root_name() && __p.root_name() != root_name())) <-- Error on this line
operator=(__p);
else
{
string_type __pathname;
if (__p.has_root_directory
....
In order to get the compiler to work with my project, is there any easy fix here?
EDIT: Build Log
-------------- Build: Debug in MullSimple-2 (compiler: GNU GCC Compiler)---------------
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -std=c++17 -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\lib\gcc_dll\mswud -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MullSimple-2\MullSimple_2Main.cpp" -o obj\Debug\MullSimple_2Main.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -std=c++17 -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\lib\gcc_dll\mswud -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MullSimple-2\non-wx\data_vars.cpp" -o obj\Debug\non-wx\data_vars.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -std=c++17 -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include -IC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\lib\gcc_dll\mswud -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MullSimple-2\non-wx\file_manager.cpp" -o obj\Debug\non-wx\file_manager.o
g++.exe -LC:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\lib\gcc_dll -o bin\Debug\MullSimple-2.exe obj\Debug\MullSimple_2App.o obj\Debug\MullSimple_2Main.o obj\Debug\non-wx\data_vars.o obj\Debug\non-wx\file_manager.o obj\Debug\non-wx\my_help_fxns.o obj\Debug\resource.res -mthreads -lwxmsw30ud_core -lwxbase30ud -lwxpngd -lwxzlibd -mwindows
In file included from C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
from C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MullSimple-2\MullSimple_2Main.cpp:19:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() && __p.root_name() != root_name()))
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:64,
from C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
from C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/string:40,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/stringimpl.h:66,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/unichar.h:15,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/strvararg.h:22,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/string.h:46,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/log.h:43,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/msw/private.h:23,
from C:\Users\gmloo\OneDrive\Desktop\wxWidgets-3.0.5\include/wx/wxprec.h:44,
from ./wx_pch.h:14,
from <command-line>:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^~~~~~~~
C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note: template argument deduction/substitution failed:
In file included from C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
from C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MullSimple-2\MullSimple_2Main.cpp:19:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note: 'std::filesystem::__cxx11::path' is not derived from 'const std::pair<_T1, _T2>'
|| (__p.has_root_name() && __p.root_name() != root_name()))
EDIT: linker settings?
I'm not sure what you mean by linking files, this is maybe the part in CodeBlocks where I can do it. What would I enter?