lewissbaker / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
3.43k stars 470 forks source link

experimental/filesystem will be removed and produce a fatal error in msvc2019 #191

Closed cathaysia closed 9 months ago

cathaysia commented 3 years ago

When I try the example of README. Here get a error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\include\experimental/filesystem(30): fatal error C1189: #error: The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft and will be REMOVED. It is superseded by the C++17 header providing std::filesystem. You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.

all the code is :

#include <iostream>
#include <cppcoro/read_only_file.hpp>
#include <cppcoro/task.hpp>

cppcoro::task<int> count_lines(std::string path)
{
    auto file = co_await cppcoro::read_only_file::open(path);

    int lineCount = 0;

    char buffer[1024];
    size_t bytesRead;
    std::uint64_t offset = 0;
    do
    {
        bytesRead = co_await file.read(offset, buffer, sizeof(buffer));
        lineCount += std::count(buffer, buffer + bytesRead, '\n');
        offset += bytesRead;
    } while (bytesRead > 0);

    co_return lineCount;
}

cppcoro::task<> usage_example()
{
    // Calling function creates a new task but doesn't start
    // executing the coroutine yet.
    cppcoro::task<int> countTask = count_lines("D:\\Documents\\docsets\\Boost.docset\\meta.json");

    // ...

    // Coroutine is only started when we later co_await the task.
    int lineCount = co_await countTask;

    std::cout << "line count = " << lineCount << std::endl;
}

int main() {

    return 0;
}
andreasbuhr commented 3 years ago

Hi, there are already pull requests fixing this issue. Until they are merged, you might want to try this fork: https://github.com/andreasbuhr/cppcoro

cathaysia commented 3 years ago

OK, thanks for your reply. :)