当前位置: 首页 > news >正文

云谷 网站建设南京制作网站建站模板公司

云谷 网站建设,南京制作网站建站模板公司,wordpress主题知更鸟,微盟小程序官网【小梦C嘎嘎——启航篇】string 使用#x1f60e; 前言#x1f64c;C语言中的字符串标准库中的string类string 比较常使用的接口对上述函数和其他函数的测试代码演示#xff1a; 总结撒花#x1f49e; #x1f60e;博客昵称#xff1a;博客小梦 #x1f60a;最喜欢的座右… 【小梦C嘎嘎——启航篇】string 使用 前言C语言中的字符串标准库中的string类string 比较常使用的接口对上述函数和其他函数的测试代码演示 总结撒花 博客昵称博客小梦 最喜欢的座右铭全神贯注的上吧 作者简介一名热爱C/C算法等技术、喜爱运动、热爱K歌、敢于追梦的小博主 博主小留言哈喽各位CSDN的uu们我是你的博客好友小梦希望我的文章可以给您带来一定的帮助话不多说文章推上欢迎大家在评论区唠嗑指正觉得好的话别忘了一键三连哦 前言 哈喽各位友友们我今天又学到了很多有趣的知识现在迫不及待的想和大家分享一下 都是精华内容可不要错过哟 C语言中的字符串 C语言中字符串是以’\0’结尾的一些字符的集合为了操作方便C标准库中提供了一些str系列的库函数但是这些库函数与字符串是分离开的不太符合OOP的思想而且底层空间需要用户自己管理稍不留神可 能还会越界访问。 标准库中的string类 string是表示字符串的字符串类该类的接口与常规容器的接口基本相同再添加了一些专门用来操作string的常规操作。string在底层实际是basic_string模板类的别名typedef basic_stringchar, char_traits, allocator string;不能操作多字节或者变长字符的序列。在使用string类时必须包含#include头文件以及using namespace std; string 比较常使用的接口 对上述函数和其他函数的测试代码演示 #includeiostream #includestring using namespace std;void Teststring1() {string s1;string s2(hello bit);string s3(s2);string s4(s2.begin(), s2. end());s1 abcdef;cout s1 endl;cout s2 endl;cout s3 endl;cout s4 endl;}void test_string3() {string s1(hello world);string s2 hello world;for (size_t i 0; i s1.size(); i){cout s1[i] ;}cout endl;string::iterator it s1.begin();while (it ! s1.end()){cout *it ;it;}cout endl;for (auto ch : s2){cout ch ;}cout endl; }void func(const string s) {//string::const_iterator it s.begin();//auto it s.begin();//while (it ! s.end())//{// //*it a;// cout *it ;// it;//}//cout endl;//string::const_reverse_iterator rit s.rbegin();/*auto rit s.rbegin();while (rit ! s.rend()){cout *rit ;rit;}cout endl;*/auto rit s.rbegin();while (rit ! s.rend()){cout *rit ;rit;}cout endl; }void test_string4() {string s1(hello world);string s2 hello world;func(s1);}void test_string5() {string s1(hello worldxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyy);string s2(s1);cout s2 endl;string s3(s1, 6, 5);cout s3 endl;string s4(s1, 6, 3);cout s4 endl;string s5(s1, 6);cout s5 endl;string s6(s1, 6, s1.size() - 6);cout s6 endl;string s7(10, a);cout s7 endl;string s8(s7.begin(), --s7.end());cout s8 endl;s8 s7;s8 xxx;s8 y; }void test_string6() {string s1(hello world);string s2 hello world;cout s1.size() endl;cout s1.capacity() endl;s1.clear();cout s1.size() endl;cout s1.capacity() endl;}void test_string7() {string s;/*s.reserve(100);for (auto ch : s){cout ch ;}cout endl;s.push_back(x);s.push_back(x);s.push_back(x);s.push_back(x);s n;s bit helloc;for (auto ch : s){cout ch;}cout endl;*///size_t old s.capacity();//cout 初始 s.capacity() endl;//for (size_t i 0; i 100; i)//{// s.push_back(x);// if (s.capacity() ! old)// {// cout 扩容: s.capacity() endl;// old s.capacity();// }//}//s.reserve(10);//cout s.capacity() endl;s hello bit;cout s.size() endl;cout s.capacity() endl;s.resize(10, a);cout s endl;cout s.size() endl;cout s.capacity() endl;}void test_string8() {string s hello;s.append( bit);cout s endl;string s3 hello;string s2;s2 s3 bit;cout s2 endl;s2 s2;cout s2 endl;//s #;//s hello;//s ss;//cout s endl;//string ret1 ss #;//string ret2 ss hello;//cout ret1 endl;//cout ret2 endl; }void test_string9() {std::string str(xxxxxxx);std::string base The quick brown fox jumps over a lazy dog.;str.assign(base);std::cout str \n;str.assign(base, 5, 10);std::cout str \n; }void test_string10() {// 空格替换为20%std::string s2(The quick brown fox jumps over a lazy dog.);string s3;for (auto ch : s2){if (ch ! ){s3 ch;}else{s3 %20;}}for (auto ch : s3){cout ch;}cout endl;printf(s2%p\n, s2.c_str());printf(s3%p\n, s3.c_str());swap(s2, s3);//s2.swap(s3);printf(s2%p\n, s2.c_str());printf(s3%p\n, s3.c_str()); }void test_string11() {string s1(test.cpp.tar.zip);//size_t i s1.find(.);size_t i s1.rfind(.);string s2 s1.substr(i);cout s2 endl;//string s3(https://legacy.cplusplus.com/reference/string/string/rfind/);//string s3(ftp://www.baidu.com/?tn65081411_1_oem_dg);string s3(https://leetcode.cn/problems/first-unique-character-in-a-string/submissions/);// 协议 https// 域名 leetcode.cn// 资源名 problems/first-unique-character-in-a-string/submissions/string sub1, sub2, sub3;i s3.find(:);sub1 s3.substr(0, i);cout sub1 endl;size_t len s3.find(/, i 3);sub2 s3.substr(i 3, len - (i 3));cout sub2 endl;sub3 s3.substr(len 1);cout sub3 endl; }void test_string12() {std::string str(Please, replace the vowels in this sentence by asterisks.);std::size_t found str.find_first_not_of(abc);while (found ! std::string::npos){str[found] *;found str.find_first_not_of(abcdefg, found 1);}std::cout str \n;/*std::string str(Please, replace the vowels in this sentence by asterisks.);std::size_t found str.find_first_of(abcd);while (found ! std::string::npos){str[found] *;found str.find_first_of(abcd, found 1);}std::cout str \n;*/}int main() {/*string s1, s2;cin s1 s2;cout s1 endl;cout s2 endl;*/string str;//cin str;getline(cin, str, !);cout str;/*size_t i str.rfind( );if (i ! string::npos){cout str.size() - (i 1) endl;}else{cout str.size() endl;}*///Teststring1();//test_string2();//test_string3();//test_string4();//test_string5();//test_string6();//test_string7();//test_string8();//test_string9();//test_string11();//test_string12();return 0; }总结撒花 本篇文章旨在分享的是string 使用知识。希望大家通过阅读此文有所收获    如果我写的有什么不好之处请在文章下方给出你宝贵的意见。如果觉得我写的好的话请点个赞赞和关注哦~
http://www.zqtcl.cn/news/595504/

相关文章:

  • 大连做网站 选领超科技网站建设公司的成本有哪些方面
  • 文章网站是怎么做的宁波网站建设lonoo
  • 做网站学cdr吗企业年金险是什么意思
  • 芜湖炎黄做的网站北京高端网站公司哪家好
  • 帮人做网站一定要先收费网站构建免费
  • 营销型网站的优缺点如何在腾讯云做网站
  • 现在做网站怎么样网站运营与管理规划书
  • 国际物流公司网站建设有关应用网站
  • 网站后台维护技能娱乐公司网站模板
  • 有建网站的公司吗p2p理财网站开发要求
  • 做私单的网站高端html5网站设计工作室织梦模板 dedecms5.7
  • 视频网站切片怎么做如何做网站结构及栏目策划
  • 公司和网站备案查询龙江网站建设公司
  • 建一个平台网站需要多少钱安徽网站建设大全
  • 做网站接广告网站注册页面怎么做
  • 西安建站价格表电脑做视频的网站比较好
  • 建筑中级职称查询网站百度指数功能模块
  • 建设网站只慧聪网怎样做网站友情链接
  • 德阳网站开发dedecms5.7装饰公司网站模板
  • 下步我院将建设网站信息保密浙江温州网络公司
  • 一键建站网站seo关键词快速排名介绍
  • 自己做网站 什么wordpress博客文章加密
  • 怎样做音视频宣传网站wordpress 推送
  • 网站图片上传代码专业的企业进销存软件定制
  • 商品网站模板wordpress文章推荐
  • 十里堡网站建设做吃的教程网站
  • 比较好的源码网站河南网站seo推广
  • 做网站推广什么好网站界面结构
  • 龙岗网站优化常见的渠道推广方式有哪些
  • wordpress 后台乱码成都百度推广优化