c++ string 对象操作
2024-10-18 18:22:45
字符串转换大小写如下:
#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 ;
}
最新文章
- Sublime Text 3 支持的热门插件推荐
- 使用TextUtils.isEmpty简单化代码
- 3942: [Usaco2015 Feb]Censoring [KMP]
- 【Git】简单地使用github当做远程共享仓库
- MySQL中distinct和group by性能比较[转]
- 在SQL中使用PL/SQL函数存在的问题
- datazen logo修改
- sqlite3安装
- WM_PAINT在微软官方定义中,wParam和lParam都没有使用,所以就被Delphi给重定义了这个消息,还增加了DC(Delphi可任意改写消息的结构)
- java String时间转为时间戳
- cs231n spring 2017 lecture9 CNN Architectures 听课笔记
- 打印星星 - Python
- [luogu P2234] [HNOI2002]营业额统计
- windows下boost编译(vs2010)
- c/c++ 读入一行不确定个数的整数
- 过滤器(Filter)与拦截器(Interceptor)的区别
- HashMap分析 + 哈希表
- ALGO-1_蓝桥杯_算法训练_区间k大数查询
- java study3
- 可以方便配合 Git 的现代编辑器