Using string literals without using namespace std

operator""s is in 2 inlined namespaces in namespace std. It basically looks like this:

namespace std
{
    inline namespace literals
    {
        inline namespace string_literals
        {
            //operator""s implementation
            //...
        }
    }
}

So, to only get the string literals, use using namespace std::string_literals;.

Alternatevely, if you want to include every literal – including the string literals (like s for seconds if you include chrono, …): using namespace std::literals;.

Depending on the situation, you might also consider using:

using std::string_literals::operator""s;

instead of importing every name from that namespace.

Note that you should still not include it in a header, at global level
(but you can do it inside inline or member functions or namespaces you control)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)