Токенизировать строку с помощью std::viewsC++

Программы на C++. Форум разработчиков
Anonymous
Токенизировать строку с помощью std::views

Сообщение Anonymous »

Я хочу перебрать токен, который я извлек из потока std::wcin, используя функции и классы библиотеки C++ std. Я попробовал это:

Код: Выделить всё

    auto input = std::views::istream(std::wcin);
auto tokens = input | std::views::lazy_split(L' ');

for (auto const& token : tokens)
{
std::wstring s1(token); // doesn't compile
std::wstring s;
s = token; // doesn't compile
s = std::wstring(token); // doesn't compile
s = std::wstring{token.begin(), token.end()}; // doesn't compile
s = std::wstring(token.begin(), token.end()); // doesn't compile
s = std::wstring(token.cbegin(), token.cend()); // doesn't compile
// action goes here - requires the token to be a string
do_something_with_the_token_string(s);
}
К сожалению, я не нашел способа преобразовать токен в wstring. Как это делается? Согласно сообщениям об ошибках, тип токена — std::ranges::lazy_split_view: :_Outer_iter::value_type.
Использование Visual Studio 17.9.1 с /std:c++20.

Подробнее здесь: https://stackoverflow.com/questions/780 ... h-stdviews

Вернуться в «C++»