base之string_piece

来源:互联网 发布:西安seo工资待遇 编辑:程序博客网 时间:2024/06/07 17:36

// A string-like object that points to a sized piece of memory.
//
// Functions or methods may use const StringPiece& parameters to accept either
// a "const char*" or a "string" value that will be implicitly converted to
// a StringPiece. The implicit conversion means that it is often appropriate
// to include this .h file in other files rather than forward-declaring
// StringPiece as would be appropriate for most other Google classes.
//
// Systematic usage of StringPiece is encouraged as it will reduce unnecessary
// conversions from "const char*" to "string" and back again.

类string对象,指向一个已知大小的内存
函数或方法可以使用const StringPiece&作为参数,参数可以是const char *string,都将隐式转换为StringPiece.隐身转换只在包含该头文件才生效,前值声明StringPiece不发生隐式转换.
推荐系统编程使用StringPiece,减少const char *->string->const char *的转换。

std::string函数区别size()和length()

两个函数等同。
size()主要用于容器类,vector.size();
length()用于字符串比较直观。

0 0
原创粉丝点击