[英]boost::interprocess::string conversion to char*
是否可以將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);
謝謝!
boost :: interprocess :: string有一個標准的c_str()方法。 我在這里找到了以下內容:
//! <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
。)
此外, 這里的文檔說
basic_string是std :: basic_string的實現,可以在托管內存段(如共享內存)中使用。 它是使用類似矢量的連續存儲實現的,因此它具有快速的c字符串轉換 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.