stl string return by const reference vs. const char*

Posted by user342673 on Stack Overflow See other posts from Stack Overflow or by user342673
Published on 2010-05-20T03:33:33Z Indexed on 2010/05/20 3:40 UTC
Read the original article Hit count: 120

Filed under:

i have a STL string member variable in my class,

class A {
public:
   const char* getData1() const { return data.c_str());
   const string& getData2() const { return _data; }
private:
   string _data;
};

getData1() vs. getData2(), which one is better?

© Stack Overflow or respective owner

Related posts about c++