如果想对string对象中的每个字符做点什么操作,目前最好的办法是使用C++11新标准提供的一种语句:范围for(range for)语句。

示例代码:

#include<iostream>
#include<string>
using namespace std; int main()
{
string str("some string");
//每行输出str中的一个字符。
for (auto c : str)
cout << c << endl;
return 0;
}

如果想要改变string对象中字符的值,必须把循环变量定义成引用类型。

示例代码:

#include<iostream>
#include<string>
#include<cctype>
using namespace std; int main()
{
string str("some string");
//转换成大写形式
for (auto &c : str)
c = toupper(c);
cout << str << endl;
return 0;
}

最新文章

  1. JetBrain WebStorm 注册码
  2. Kafka 快速起步(作者:杜亦舒)
  3. poj 2184 Cow Exhibition
  4. Android Service 系统服务
  5. 宣布发布 Windows Azure ExpressRoute,宣告与 Level 3 建立全新的合作伙伴关系并推出关于其他 Azure 服务令人振奋的更新
  6. html+css实现图片的层布局
  7. Linux内核进程管理
  8. Hibernate-----关系映射 重点!!!
  9. Linux中后台执行任务
  10. jQuery测验题
  11. js二维码插件总结
  12. CCF CSP 认证
  13. 内置函数_range()
  14. USB to UART
  15. Birdman Quotes
  16. vue-cli+webpack在生成的项目中使用bootstrap方法(二)
  17. 使用Linux命令行测试网速-----speedtest-cli
  18. 悟空模式-java-工厂方法模式
  19. 关于django过滤器的使用
  20. Ubuntu14.04下Cloudera安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)(在线或离线)

热门文章

  1. 微信小程序腾讯云配置Tomcat https端口
  2. springboot+mybatisplus 测试代码生成
  3. 搭建两个节点的大数据集群-1.hdfs集群
  4. sqlite内存数据库和文件数据库的同步[转]
  5. mysql-介绍
  6. Dynamics 365-下载新版本的开发工具
  7. 关于在各种int类型选择时的考虑
  8. linux-课题练习1
  9. DAG上dp思想
  10. 2.PostgreSQL安装详细步骤(windows)【转】