Creating an array of string_view elements throws error: unable to find string literal operator ‘operator""sv’ with

Creating an array of string_view elements throws error: unable to find string literal operator ‘operator""sv’ with

我有以下(修改过的)代码,我想在其中创建一个 string_view 类型对象的数组。

我在编译对应每一行时看到这个错误

unable to find string literal operator ‘operator""sv’ with ‘const char [8]’, ‘long unsigned int’ arguments
     "Sensor2"sv,

代码:

#include <iostream>
#include <array>
#include <string_view>

struct Abc
{
    static constexpr std::array<std::string_view, 6> SomeValues = {
        "Sensor1"sv,
        "Sensor2"sv,
        "Actuator1"sv,
        "Actuator2"sv,
        "Cpu1"sv,
        "Cpu2"sv
    };
    
};


int main()
{
    Abc abc;
    
    std::cout<<abc.SomeValues[3];

    return 0;
}

你需要 using namespace std::literals;.

另见