passing string literal to std::map::find(..)

Posted by ra170 on Stack Overflow See other posts from Stack Overflow or by ra170
Published on 2010-03-17T16:07:36Z Indexed on 2010/03/17 16:11 UTC
Read the original article Hit count: 243

Filed under:
|

I've got a std::map. I'm passing string literal to find method. Obviously, I can pass a string literal such as

.find("blah");

However, I wanted to declare it upfront, instead of hardcoding the string, so I have couple of choices now:

const std::string mystring = "blah";
const char mystring[] = "blah";
static const char * mystring = "blah";

They all work. (or at least compile). My question is, which one should I use? what's the advantage/distavantage over of the other?

© Stack Overflow or respective owner

Related posts about c++

Related posts about string