随笔分类 -  c++

摘要:void pop_back();//弹出最后一个字符 #include <string>#include <iostream> using namespace std;int main(){ string str("hello world!"); str.pop_back(); cout << st 阅读全文
posted @ 2020-01-10 20:15 MoonXu 阅读(497) 评论(0) 推荐(0) 编辑
摘要:string (1) string& insert (size_t pos, const string& str); substring (2) string& insert (size_t pos, const string& str, size_t subpos, size_t sublen); 阅读全文
posted @ 2019-12-31 18:29 MoonXu 阅读(437) 评论(0) 推荐(0) 编辑
摘要:allocator_type get_allocator() const noexcept; 返回和对象相关的分配器的一个拷贝 #include <iostream>#include <string>#include <vector>using namespace std;int main(){ v 阅读全文
posted @ 2019-12-31 17:56 MoonXu 阅读(436) 评论(0) 推荐(0) 编辑
摘要:char& front(); const char& front() const;功能:返回string对象的首个字符,可以改变它的值 #include <string>#include <iostream> using namespace std; int main(){ string s1("t 阅读全文
posted @ 2019-12-24 23:33 MoonXu 阅读(357) 评论(0) 推荐(0) 编辑
摘要:string (1) size_t find_last_of (const string& str, size_t pos = npos) const noexcept; c-string (2) size_t find_last_of (const char* s, size_t pos = np 阅读全文
posted @ 2019-12-24 14:07 MoonXu 阅读(582) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <string> using namespace std;int main(){ string s1("abcdemyyngl"); string s2("mngf"); size_t n = s1.find_last_not_of(s2); 阅读全文
posted @ 2019-12-24 12:19 MoonXu 阅读(680) 评论(0) 推荐(0) 编辑
摘要:string (1) size_t find_first_of (const string& str, size_t pos = 0) const noexcept; c-string (2) size_t find_first_of (const char* s, size_t pos = 0) 阅读全文
posted @ 2019-12-24 11:49 MoonXu 阅读(583) 评论(0) 推荐(0) 编辑
摘要:string (1) size_t find_first_not_of (const string& str, size_t pos = 0) const noexcept; c-string (2) size_t find_first_not_of (const char* s, size_t p 阅读全文
posted @ 2019-12-24 10:41 MoonXu 阅读(547) 评论(0) 推荐(0) 编辑
摘要:sequence (1) string& erase (size_t pos = 0, size_t len = npos);两个参数都有默认值,传递的唯一参数匹配第一个 character (2) iterator erase (const_iterator p);//擦除迭代器指定的一个字符 r 阅读全文
posted @ 2019-12-24 09:37 MoonXu 阅读(243) 评论(0) 推荐(0) 编辑
摘要:bool empty() const noexcept;注:判断string对象是否为空,为空返回true #include <iostream>#include <string> using namespace std; int main(){ string line; string conten 阅读全文
posted @ 2019-12-24 09:07 MoonXu 阅读(249) 评论(0) 推荐(0) 编辑
摘要:const char* data() const noexcept;注:同c_str #include <iostream>#include <string>#include <cstring>using namespace std;int main(){ string s1("hellolyy") 阅读全文
posted @ 2019-12-24 08:59 MoonXu 阅读(209) 评论(0) 推荐(0) 编辑
摘要:const char* c_str() const noexcept;功能:返回c风格字符转 #include <iostream>#include <string>#include <cstring>using namespace std; int main(){ string s1("i lov 阅读全文
posted @ 2019-12-23 19:04 MoonXu 阅读(152) 评论(0) 推荐(0) 编辑
摘要:const_reverse_iterator crbegin() const noexcept;功能:crbegin是最后一个字符,crend第一个字符的前一个。迭代器向左移动是“+”,向右移动是“-” #include <iostream>#include <string> using names 阅读全文
posted @ 2019-12-23 18:15 MoonXu 阅读(336) 评论(0) 推荐(0) 编辑
摘要:size_t copy (char* s, size_t len, size_t pos = 0) const;功能:把string的pos位置开始的len字节copy到s注意:s的最后要手动添加字符串结束标志 #include <iostream>#include <string> using n 阅读全文
posted @ 2019-12-23 18:03 MoonXu 阅读(477) 评论(0) 推荐(0) 编辑
摘要:void clear() noexcept;功能:把string对象置为空 #include <iostream>#include <string> using namespace std; int main(){ char c; string str; cout << "please enter 阅读全文
posted @ 2019-12-23 17:41 MoonXu 阅读(219) 评论(0) 推荐(0) 编辑
摘要:const_iterator cbegin() const noexcept; const_iterator cend() const noexcept;注:返回常量迭代器,不能修改 #include <iostream>#include <string> using namespace std; 阅读全文
posted @ 2019-12-23 15:21 MoonXu 阅读(492) 评论(0) 推荐(0) 编辑
摘要:size_t capacity() const noexcept; #include <iostream>#include <string> using namespace std; int main(){ string s1("hello"); cout << "capacity:" << s1. 阅读全文
posted @ 2019-12-23 13:39 MoonXu 阅读(230) 评论(0) 推荐(0) 编辑
摘要:iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; #include <iostream>#in 阅读全文
posted @ 2019-12-23 13:24 MoonXu 阅读(199) 评论(0) 推荐(0) 编辑
摘要:char& back(); const char& back() const; #include <iostream>#include <string> using namespace std;int main(){ string s1("hello"); cout << s1.back() << 阅读全文
posted @ 2019-12-23 13:18 MoonXu 阅读(190) 评论(0) 推荐(0) 编辑
摘要:char& at (size_t pos); const char& at (size_t pos) const; #include <string>#include <iostream> using namespace std;int main(){ string s1("test"); for( 阅读全文
posted @ 2019-12-23 10:25 MoonXu 阅读(165) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示