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

Flaviu_ 971 Reputation points
2024-06-24T13:36:57.3133333+00:00

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?

C++
C++
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,629 questions
{count} votes

Accepted answer
  1. Minxin Yu 10,871 Reputation points Microsoft Vendor
    2024-06-25T01:26:14.2066667+00:00

    Hi, @Flaviu_

    From the doc: https://learn.microsoft.com/en-us/cpp/standard-library/string-view?view=msvc-170
    Requirements

    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 _STL_COMPILER_PREPROCESSOR
    #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 // _STL_COMPILER_PREPROCESSOR
    #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