Boost :: interprocess :: convert string to char *

Is it possible to convert a boost::interprocess::stringto std::stringor to const char*? Something like c_str()...

eg:.

boost::interprocess::string is = "Hello world";
const char* ps = is.c_str();    // something similar
printf("%s", ps);

I could even get a copy of the string in a block without shared memory.

eg:.

boost::interprocess::string is = "Hello world";
const char cs[100];
strcpy(cs, is.c_str());    // something similar
printf("%s", cs);

Thank!

+3
source share
1 answer

boost :: interprocess :: string has the standard c_str () method. I found it here :

//! <b>Returns</b>: Returns a pointer to a null-terminated array of characters 
//!   representing the string contents. For any string s it is guaranteed 
//!   that the first s.size() characters in the array pointed to by s.c_str() 
//!   are equal to the character in s, and that s.c_str()[s.size()] is a null 
//!   character. Note, however, that it not necessarily the first null character. 
//!   Characters within a string are permitted to be null. 
const CharT* c_str() const 
{  return containers_detail::get_pointer(this->priv_addr()); }

(This for basic_string. stringIs an instance of the template in which the template parameter CharTis equal char.)

In addition, the documentation here says

basic_string - std:: basic_string , . - , ...

+3

Source: https://habr.com/ru/post/1764921/


All Articles