Как решить ошибку которая показывает на стандартную библиотеку?

Пишу небольшой лексический анализатор, но когда пытаюсь скомпилировать, пишется ошибка которая и показывает на стандартную библиотеку:

C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' (or there is no acceptable conversion)

Код на который показывает ошибка:

   

template <class _Elem, class _Traits, class _BidIt>
basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, const sub_match<_BidIt>& _Match) {
    return _Ostr << _Match.str(); // <- ошибка тут
}

Мой код (простите за грязный код, не смог повторить ошибку в чистом проекте):

   

if (this->_position.chr >= this->_origin.length()) {
    return NULL;
}

std::wsmatch match;
std::wstring temp = this->_origin.substr(this->_position.chr);
if (temp[0] == '\0')
    return NULL;
bool isMatch = false;
DS::LexemeType* type;
for (int i = 0; i < DS::types.size(); i++) {
    type = DS::types[i];
    if (std::regex_search(temp, match, type->getRegex())) {
        if (match.prefix().length() != 0)
            continue;
        std::cout << type->getName() << "(" << match[0] << ")\n";
        if (type->getID() == DS::LexemeType::ID::OTHER_NEWLINE) {
            this->_position.inLine = 0;
            this->_position.line++;
        }
        this->_position.chr += match[0].length();
        this->_position.inLine += match[0].length();
        isMatch = true;
        break;
    }
}
if (isMatch)
    return new Lexeme(match[0], *type, this->_position);

throw std::runtime_error("Wrong lexeme at " + std::to_string(this->_position.line) + ":" + std::to_string(this->_position.inLine) + "");

А также то как я создаю wregex объект:

std::wregex(L"^[0-9a-zA-Z]+")

Ещё раз повторю что бы убрать недопонимание, ошибка показывает не на мой код, а на код в библиотеке (и я понимаю что это из-за меня).

Заранее спасибо за помощь.


Ответы (1 шт):

Автор решения: Harry

Читаем внимательно:

C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' (or there is no acceptable conversion)

binary '<<'

Ага, итак, проблема в операторе <<. Какая же?

no operator found which takes a right-hand operand of type

Не найден оператор, который принимает справа величину типа... Какого типа?

std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>

Т.е. строка с "широкими" символами wchar_t. Или, короче говоря, wstring.

А теперь сами посмотрите — пытаетесь выводить wstring в cout? Вот и ответ. wstring и выводиться должна в wcout...

Кстати говоря: стоит ввести строку с кодом ошибки и проГУГЛяться в Интернет — как вы тут же получите исчерпывающую статью о ней.

Кстати, у меня в VC++ 2019 показывает именно строку кода, не библиотеки:

введите сюда описание изображения

→ Ссылка