是否可以将boost::interprocess::string转换为std::string或const char*?像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);谢谢!
发布于 2010-09-17 10:33:33
string有一个标准的c_str()方法。我找到了下面的here
//! <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()); }(这是为basic_string准备的。string是一个模板实例化,其中CharT模板参数为char。)
此外,documentation here表示
basic_string是std::basic_string的实现,可以在共享内存等托管内存段中使用。它是使用类似向量的连续存储实现的,因此它具有快速的c字符串转换...
https://stackoverflow.com/questions/3719460
复制相似问题