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

广西建设厅网站地址网站建设推广服务

广西建设厅网站地址,网站建设推广服务,长沙微网站开发,好站站网站建设推广在C中&#xff0c; std::string 类有许多常用函数&#xff0c;以下是一些常见的&#xff1a; 1. length() 或 size() &#xff1a;返回字符串的长度&#xff08;字符个数&#xff09;&#xff0c;二者功能相同。例如&#xff1a; #include <iostream> #include <str…

在C++中, std::string 类有许多常用函数,以下是一些常见的:

1. length() 或 size() :返回字符串的长度(字符个数),二者功能相同。例如:
#include <iostream>
#include <string>
int main() {std::string str = "hello";std::cout << str.length() << std::endl; std::cout << str.size() << std::endl; return 0;
}
2. empty() :检查字符串是否为空,为空返回 true ,否则返回 false 。
#include <iostream>
#include <string>
int main() {std::string str1 = "";std::string str2 = "world";std::cout << std::boolalpha << str1.empty() << std::endl; std::cout << std::boolalpha << str2.empty() << std::endl; return 0;
}
3. append() :在字符串末尾追加另一个字符串或字符序列。
#include <iostream>
#include <string>
int main() {std::string str = "hello";str.append(" world");std::cout << str << std::endl; return 0;
}
pop_back():删除字符串最后一个字符
str。pop_back():
4. substr() :返回字符串的子串。接受起始位置和长度作为参数。
cpp#include <iostream>
#include <string>
int main() {std::string str = "hello world";std::string sub = str.substr(0, 5);std::cout << sub << std::endl; return 0;
}
5. find() :在字符串中查找指定子串或字符的位置,返回首次出现的位置索引,若未找到返回 std::string::npos 。
cpp
#include <iostream>
#include <string>
int main() {std::string str = "hello world";size_t pos = str.find("world");if (pos != std::string::npos) {std::cout << "子串位置: " << pos << std::endl; }return 0;
}
6. replace() :用新的子串替换字符串中指定的子串。
#include <iostream>
#include <string>
int main() {std::string str = "hello world";str.replace(6, 5, "C++");std::cout << str << std::endl; return 0;
}
7. c_str() :返回一个指向以空字符结尾的C风格字符串的指针。常用于与C语言函数接口。
#include <iostream>
#include <string>
#include <cstdio>
int main() {std::string str = "hello";const char* cstr = str.c_str();printf("%s\n", cstr); return 0;
}
http://www.cadmedia.cn/news/7915.html

相关文章:

  • 自己建设的网站在日本有市场吗疫情防控最新通告
  • 优化网站排名茂名厂商关键词排名顾问
  • 网站建设是不是要有营业执照百家号查询排名数据查询
  • 南京英文网站制作网络营销软件
  • 不错的网站开发公司seo关键词优化排名软件
  • 网站建设服务方案ppt自媒体135网站免费下载安装
  • 招全国代理经销q群排名优化软件
  • 自己建设的网站怎么上传图片什么叫网络营销
  • 重庆忠县网站建设报价电商营销
  • 福州网站建设外贸目录型搜索引擎有哪些
  • 重庆网站建设重庆零臻科技价百度快照投诉中心官网
  • 网站推广的实际案例热点新闻事件及评论
  • 站酷网官网长沙百度网站推广公司
  • 手机网站建设经典教程免费seo关键词优化服务
  • 长沙住房和建设局网站福州seo代理计费
  • 注册公司注册资金多少为好廊坊百度关键词优化怎么做
  • 在线设计平台的发展趋势重庆搜索引擎seo
  • 哪个网站做加盟国际最新新闻
  • 招标文件免费下载网站建立网站的几个步骤
  • 品牌网站推广软件seo技术有哪些
  • 凡客优品家居官网杭州seo顾问
  • 浏阳网站建设tvshown今日关注
  • 深圳企业网站制作中心怎么免费给自己建网站
  • 福州网站建设推广网页设计需要学什么软件
  • 北京手机建站模板个人网站搭建
  • 新动力网站建设公司网络宣传的方法有哪些
  • 网站建设估价seo培训费用
  • 企业网站模板建立流程百度建站平台官网
  • 人大网站建设方案 文库免费大数据查询平台
  • 沈阳哪个公司可以做网站竞价托管代运营多少钱