Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have the following (modified) code where I want to create an array of string_view type objects.

I see this error when compiling corresponding to each line

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

The code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#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;
}

>Solution :

You need using namespace std::literals;.

See also this question.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading