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");

}

相关推荐
virus59454 小时前
悟空CRM mybatis-3.5.3-mapper.dtd错误解决方案
java·开发语言·mybatis
一匹电信狗4 小时前
【LeetCode_547_990】并查集的应用——省份数量 + 等式方程的可满足性
c++·算法·leetcode·职场和发展·stl
初次见面我叫泰隆4 小时前
Qt——3、常用控件
开发语言·qt·客户端
鱼跃鹰飞5 小时前
Leetcode会员尊享100题:270.最接近的二叉树值
数据结构·算法·leetcode
Queenie_Charlie5 小时前
小陶的疑惑2
数据结构·c++·树状数组
无小道5 小时前
Qt——QWidget
开发语言·qt
时艰.6 小时前
Java 并发编程之 CAS 与 Atomic 原子操作类
java·开发语言
梵刹古音6 小时前
【C语言】 函数基础与定义
c语言·开发语言·算法
筵陌6 小时前
算法:模拟
算法
梵刹古音6 小时前
【C语言】 结构化编程与选择结构
c语言·开发语言·嵌入式