1

When I configurate the source code in Cmake with configurator Mingw Makefile, I get no errors, when I proceed to the terminal and write "make" in the correct folder, I get the following error in termianl:

error: cannot convert 'const value_type*' {aka 'const wchar_t*'} to 'const char*'

This line causing this problem is this:

int nbr = (int) std::strtol(entry.path().filename().c_str(), nullptr, 10);

Previously I've run the exact same code on Mac with 0 issues. Running on Windows 11. Any ideas on how this can be solved?

  • It seems you're using wide-character (`wchar_t`) strings, not narrow character (`char`) strings. The `std::strtol` function expects a narrow character string. What is `entry`? What does its `path()` function return? What does its `filename()` function return? Please create a proper [mre] to show us. – Some programmer dude Jan 16 '22 at 15:28
  • 1
    Also note that whenever you feel the need to do a C-style cast (like you do with `(int)`) you should take that as a sign you're probably doing something wrong. Why aren't you using [`std::stoi`](https://en.cppreference.com/w/cpp/string/basic_string/stol) if you want to convert a `std::string` to an `int`? Note that since `std::stoi` is a C++ function (unlike `std::strtol`), it has overload for the wide character `std::wstring` (which would solve your problem). – Some programmer dude Jan 16 '22 at 15:30
  • 1
    I assume you're using `std::filesystem::path` which is `wchar_t` based on windows, but not on mac. If this is indeed the case, use the [`std::filesystem::path::string`](https://en.cppreference.com/w/cpp/filesystem/path/string) function or `std::wcstol`(windows only)... – fabian Jan 16 '22 at 15:56

0 Answers0