to_string().c_str()

Could somebody explain the meaning of bold letters in below statement
 
get_time().to_string().c_str()
It call get_time() function (method?) and then call to_string() method of whatever is returned (probably std::string). Then call c_str() on it.

It is roughtly equivalent to:
1
2
3
auto x = get_time();
auto y = x.to_string();
y.c_str();


I want to warn that if there is std::string involved, then pointer returned by c_str() will become invalid immediately after this expression finishes. Be careful with it.
http://en.cppreference.com/w/cpp/string/basic_string/to_string

http://www.cplusplus.com/reference/string/string/c_str/

first one will get you back a std::string, and the second one spits the string out in an old-school c-style array (char array).

Topic archived. No new replies allowed.