cppcoro icon indicating copy to clipboard operation
cppcoro copied to clipboard

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

Open cathaysia opened this issue 3 years ago • 2 comments

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;
}

cathaysia avatar Jan 16 '21 12:01 cathaysia

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

andreasbuhr avatar Jan 16 '21 12:01 andreasbuhr

OK, thanks for your reply. :)

cathaysia avatar Jan 16 '21 12:01 cathaysia