Thread: User-defined literals, C++14

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    203

    User-defined literals, C++14

    I'm trying to insert C++14 style user-defined literal suffixes into my code:
    Code:
    # include <iostream>
    # include <string>
    
    int main()
    {
        auto str = "hello world"s;
    }
    Getting some variant of the following error message with GCC 4.9 (via C::B), MinGW7.1 (via nuwen-distro) and also online at coliru and cpp.sh:
    Code:
    error: unable to find numeric literal operator 'operator""i'|
    note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes|
    ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
    Trying to compile with either of the above doesn't help either. Any suggestions re using such literals v welcome. Thanks.

  2. #2
    Guest
    Guest
    Are you sure that suffix exists? There is a ""s one in std::chrono, but that's for seconds.

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    This works on VS 2015 CE

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std::string_literals;
    
    int main()
    {
      auto str = "hello world"s;
    }
    User-defined literals — Part I | Andrzej's C++ blog

    See first response from Andrzej Krzemieński

  4. #4
    Guest
    Guest
    Yup, that works here too. So the feature was not in scope Sean, that's all.

  5. #5
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    Thanks, that clears it up.

  6. #6
    Registered User
    Join Date
    Sep 2017
    Posts
    1
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. User-defined function
    By ulti-killer in forum C Programming
    Replies: 5
    Last Post: 06-10-2012, 05:27 AM
  2. User defined Header
    By $l4xklynx in forum C++ Programming
    Replies: 33
    Last Post: 12-01-2008, 06:09 PM
  3. User defined functions
    By alexpos in forum C Programming
    Replies: 2
    Last Post: 10-23-2005, 02:53 PM
  4. New to user defined functions
    By Extropian in forum C Programming
    Replies: 4
    Last Post: 08-15-2005, 10:45 PM
  5. user-defined iterator
    By ygfperson in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2003, 08:14 PM

Tags for this Thread