error C2039: 'string_view': is not a member of 'std'

Flaviu_ 971 Reputation points

I have installed a fresh VS2022 (community). I created a MFC app, and I compiled and worked fine. I put the following line of code, in a header, lets say class CMFCApplication1Doc : public CDocument:

// MFCApplication1Doc.h : interface of the CMFCApplication1Doc class
#pragma once
constexpr std::string_view whitespaces{ " \t\n\r" };

And from that point, I got:

error C2039: 'string_view': is not a member of 'std'

Of course, I setup c++ 20 standard:

User's image

What I am missing here?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,625 questions
{count} votes

Accepted answer
  1. Minxin Yu 10,791 Reputation points Microsoft Vendor

    Hi, @Flaviu_

    From the doc:

    Header: <string_view>

    Namespace: std

    You can also use header files that include xstring, such as iostream, string.

    string_view header

    #ifndef _STRING_VIEW_
    #define _STRING_VIEW_
    #include <yvals.h>
    #if !_HAS_CXX17
    _EMIT_STL_WARNING(STL4038, "The contents of <string_view> are available only with C++17 or later.");
    #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv
    #include <xstring>
    #endif // ^^^ _HAS_CXX17 ^^^
    #endif // _STRING_VIEW_

    Best regards,

    Minxin Yu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful