Thread: Creating a C++ std::string literal

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485

    Creating a C++ std::string literal

    Hello,

    Is there a way to create a string literal from the stl string class? I have a function that takes a stl string as argument, but using a quoted string as in: func("string"); creates a basic C string literal. So is there something similar for the stl string.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    If your parameter is a std::string it should be converted to a std::string by the compiler. You could also do something like:
    Code:
    funct(std::string("string"));
    Jim

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Thank you! I may have confused some warnings I got here I think.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Post the warnings and maybe I can help. But I do have the feeling that the word const will be contained in your warnings.

    Jim

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Thanks, but the warnings are now gone. The confusion came from the fact that the warning referred to an object<std::basic_string<char> >*, where the pointer value was the central part. I just prematurely latched on to the std::basic_string part, without reason.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modifying a string literal
    By Richardcavell in forum C Programming
    Replies: 3
    Last Post: 02-15-2011, 12:26 AM
  2. Modifying a string literal.
    By Eman in forum C++ Programming
    Replies: 45
    Last Post: 12-30-2010, 06:37 PM
  3. string literal assignment
    By @nthony in forum C Programming
    Replies: 1
    Last Post: 03-13-2009, 12:06 PM
  4. Replies: 7
    Last Post: 07-18-2005, 08:43 AM
  5. String literal
    By subdene in forum C++ Programming
    Replies: 5
    Last Post: 11-05-2002, 02:10 PM