先把<string> 包含上再说。
1.string::size_type idx = filename.find('K');
if(idx == string::npos)
{
//查找失败的处理,idx必须是 size_type 类型的,不可以是其他类型,否则会出错
// string 不是一个C-string串,所以了,没有结尾的 '/0'
//npos 类似于‘/0’
}
2. 在filename.substr(filename.find('.')) 中,如果找不到‘.’ 就会抛出异常 (因为此处返回值为子串的起始索引)
在filename.substr(0, filename.find('.')) 中,如果找不到‘.’ 就会不会抛出异常。而会返回整个串。
3. endIdx = line.find_first_of (delims, begIdx) 从begIdx开始,找到line中第一次出现delims中所含字符的位置。
同理,还有find_first_not_of();
4.line[] 字符串进行下标访问,但是没有合法检验,line.at()就会有合法检验了。参见这段程序:
5.wstring 是针对wchar_t而预先定义的特别化版本:
6. basic_string<>被定义为所有字符串型别的基本模版类别 。
namespace std {
template<class charT,
class traits = char_traits<charT>,
class Allocator = allocator<charT> >
class basic_string;
}
其中,string 和wstring是两个预先定义的特化版本。
7.STL中的string 并不支持正则表达式,文本处理(大写化,大小写不计的字符串比较)