String boost::进程间::字符串到字符的转换*

String boost::进程间::字符串到字符的转换*,string,boost,char,interprocess,String,Boost,Char,Interprocess,是否可以将boost::interprocess::string转换为std::string或const char*?类似于c_str() 例如: 我甚至可以在非共享内存块中获取字符串的副本 例如: 谢谢大家! boost::进程间::string有一个标准的c_str()方法。我发现: /!返回:返回指向以null结尾的字符数组的指针 //! 表示字符串的内容。对于任何字符串s,它都是有保证的 //! s.c_str()指向的数组中的第一个s.size()字符 //! 等于s中的字

是否可以将
boost::interprocess::string
转换为
std::string
const char*
?类似于
c_str()

例如:

我甚至可以在非共享内存块中获取字符串的副本

例如:


谢谢大家!

boost::进程间::string有一个标准的c_str()方法。我发现:

/!返回:返回指向以null结尾的字符数组的指针
//!   表示字符串的内容。对于任何字符串s,它都是有保证的
//!   s.c_str()指向的数组中的第一个s.size()字符
//!   等于s中的字符,且s.c_str()[s.size()]为空
//!   性格但是,请注意,它不一定是第一个空字符。
//!   字符串中的字符允许为空。
常量图表*c_str()常量
{return containers_detail::get_指针(this->priv_addr());}
(这是用于
basic_string
string
的模板实例化,其中
图表
模板参数为
字符

文件还说

基本字符串是 std::准备在中使用的基本_字符串 托管内存段,如共享 记忆。它是使用 类似矢量的连续存储,因此 有快速的c字符串转换

谢谢你的法语。c_str()是我最初尝试的,我不知道为什么它不起作用。现在一切都好了。
boost::interprocess::string is = "Hello world";
const char* ps = is.c_str();    // something similar
printf("%s", ps);
boost::interprocess::string is = "Hello world";
const char cs[100];
strcpy(cs, is.c_str());    // something similar
printf("%s", cs);
//! <b>Returns</b>: Returns a pointer to a null-terminated array of characters 
//!   representing the string's 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()); }