c++ string 对象操作
字符串转换大小写如下:
#include "stdafx.h"
#include <iostream>
#include <string> using namespace std; int main()
{
string str = "helloworld";
for (auto begin = str.begin(); begin != str.end(); ++begin)
{
*begin = toupper(*begin);
} cout << str << endl; system("PAUSE");
return ;
}
删除字符串中所有的大写字母:
#include "stdafx.h"
#include <iostream>
#include <string> using namespace std; int main()
{
string str("helloWorld");
for (auto begin = str.begin(); begin != str.end();)
{
if (isupper(*begin))
{
begin = str.erase(begin);
continue;
}
++begin;
} cout << str << endl; system("PAUSE");
return ;
}
用vector对象初始化string :
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector> using namespace std; int main()
{
vector<char> vect;
char arry[] = {'h','e','l','l','o'};
vect.insert(vect.begin(),arry,arry+);
char *pc = new char[vect.size()+];
int i = ;
for (vector<char>::iterator begin = vect.begin(); begin != vect.end(); ++begin)
{
pc[i] = *begin;
++i;
}
pc[vect.size()] = '\0';
string str(pc);
delete [] pc;
cout << str << endl;
system("PAUSE");
return ;
}
c++ string 对象操作的更多相关文章
- C++ STL string对象操作汇总
string对象 C语言只提供了一个char类型用来处理字符,而对于字符串,只能通过字符串数组来处理,显得十分不便.C++STL提供了string基本字符系列容器来处理字符串,可以把string理解为 ...
- string的+操作与StringBuilder对象
习惯在C#代码中写str+="xxx";这样代码的请注意啦,如果这种操作是针对单个变量作很多次叠加操作的,很有可能导致性能降低. 大家都知道string与StringBuilder ...
- string 对象及其操作
标准库类型string 标准库类型string表示可变长的字符序列,使用string类型必须首先包含string头文件.作为标准库的一部分,string定义在命名空间std中.接下来的示例都假定了已包 ...
- C风格字符串和C++ string 对象赋值操作的性能比较
<<C++ Primer>> 第四版 Exercise Section 4.3.1 部分Exercise 4.2.9 习题如下: 在自己本机执行如下程序,记录程序执行时间: # ...
- (8)string对象上的操作1
读写操作 //读写string对象的测试.//本程序输入两string类,输出两string类. #include <iostream> #include <string> ...
- Python把json格式的string对象转变成dict对象操作、Python3不能使用urllib2、urllib.parse.urlencode(params).encode(encoding='UTF8')
son格式的string对象转变成dict对象操作 content=eval(content)#json字典转化 Python3不能使用urllib2 直接使用urllib.request替换urll ...
- js String对象中常用方法小结(字符串操作)
1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: index将被处理字符的从零开始计数的编号.有效值为0到字符 ...
- (9)string对象上的操作2
比较string对象的比较运算符 这种由string类定义的几种比较字符串的运算符能逐一比较string对象中的字符(对大小写敏感).
- JavaScript String对象
本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...
随机推荐
- easyUI 添加排序到datagrid
http://www.cnblogs.com/javaexam2/archive/2012/08/10/2632645.html
- es6笔记3^_^object
一.destructuring ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构Destructuring. //es5 if(1){ let cat = 'ken'; le ...
- Linux笔记(七) - 网络命令
(1)给用户发信息:write例:write admin(ctrl+d结束)(2)发广播信息:wall例:wall hello world!(3)测试网络连通性:ping-c 发送次数例:ping - ...
- HDU4127(IDA*)
Flood-it! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- CodeForces 512B(区间dp)
D - Fox And Jumping Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- Redis系列二(yum切换为网易163)
这个可能和Redis没有直接的关系... 是我在yum install的时候发现centos的yum实在是太慢,上网查了下.网易163有个yum镜像,为了让CentOS6使用速度更快的YUM更新源,可 ...
- 如何用webbrowser获取ajax动态生成的网页的源码?
1.步骤一:修改IE内核的版本(这个方法厉害了) public Form1() { InitializeComponent();int BrowserVer, RegVal; // get the i ...
- JDK分析工具&JVM垃圾回收(转)
转自:http://blog.163.com/itjin45@126/blog/static/10510751320144201519454/ 官方手册:http://docs.oracle.com/ ...
- 内功心法 -- java.util.ArrayList<E> (1)
写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------下文主要对java.util ...
- samentic 在IE9 不支持 transition 的解决方案
本文原文链接为:http://www.cnblogs.com/jying/p/6377696.html ,转载请注明出处. 在使用samentic过程中遇到 IE9 下报如下错误: 查阅了好多资料终 ...