C++语言string类的相关函数
一、string的长度、容量
返回字符串对象的长度
1. size()
2. length()
返回已经分配给字符串对象的长度(容量)
3. capacity()
返回字符串能够存储的最大长度的字节数
4. max_size()
string str("Test string");
cout<<str.size();
cout<<str.length();
cout<<str.capacity();
cout<<str.max_size(); //字符串能够存储的最大长度不会因字符串的改变而改变
二、find查找字符串的内容
find查找的几种重载函数
size_t find(const string &str, size_t pos=0) const; //指定起始位置和所要查找的字符串字符串
size_t find(const char* s, size_t pos=0) const; //查找C风格的字符串,如果没有给定起始位置,则从0开始查找
size_t find(const char* s, size_t pos, size_type n) const;
size_t find(char c, size_t pos=0) const noexcept; //在指定的起始位置,查找指定的字符
find函数的用法
string str("There are two needles in this haystack with needles ...");
string str2("needle");
size_t found <