c++ string 容器

#include <iostream>

#include <string>

#include <fstream>

#include <vector>

#include <algorithm>

using namespace std;

void test01()

{

string s1;

s1 = "hello world";

cout<<s1<<endl;

const char *str = "hello world";

string s2(str);

cout<<s2<<endl;

string s3(s2);

cout<<s3<<endl;

string s4(10,'a');

cout<<s4<<endl;

}

void test02()

{

string str1="ddd";

str1+="aaa";

cout<<str1<<endl;

}

void test03()

{

string ls="adadad";

int pos=ls.find("da");

cout<<pos<<endl;

}

void test04()

{

string str1="hello world";

string str2="hello";

cout<<str1.compare(str2)<<endl;

}

void test05()

{

string se="hello world";

for(int i=0;i<se.size();i++)

{

cout<<se[i]<<endl;

}

}

void test06()

{

string str22="hello";

str22.insert(1,"111");

cout<<str22<<endl;

}

void test07()

{

string strw1="helloworld";

string substr=strw1.substr(1,3);

cout<<substr<<endl;

}

void test08()

{

string email="zhangsan@163.com";

int pos=email.find("@");

cout<<pos<<endl;

string name=email.substr(0,pos);

cout<<name<<endl;

}

int main()

{

test02();

test01();

test03();

test04();

test05();

test06();

test07();

test08();

system("pause");

}

相关推荐
你怎么知道我是队长17 分钟前
C语言---头文件
c语言·开发语言
期待のcode22 分钟前
Java虚拟机的运行模式
java·开发语言·jvm
hqwest30 分钟前
码上通QT实战25--报警页面01-报警布局设计
开发语言·qt·qwidget·ui设计·qt布局控件
a程序小傲34 分钟前
京东Java面试被问:动态规划的状态压缩和优化技巧
java·开发语言·mysql·算法·adb·postgresql·深度优先
HellowAmy1 小时前
我的C++规范 - 玩一个小游戏
开发语言·c++·代码规范
自学不成才1 小时前
深度复盘:一次flutter应用基于内存取证的黑盒加密破解实录并完善算法推理助手
c++·python·算法·数据挖掘
June`1 小时前
全排列与子集算法精解
算法·leetcode·深度优先
徐先生 @_@|||1 小时前
Palantir Foundry 五层架构模型详解
开发语言·python·深度学习·算法·机器学习·架构
tang777892 小时前
爬虫如何绕过绕过“5秒盾”Cloudflare:从浏览器指纹模拟到Rust求解之不完全指南
开发语言·爬虫·rust·cloudflare