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

}

相关推荐
自由与自然2 小时前
栅格布局常用用法
开发语言·前端·javascript
_codemonster2 小时前
python易混淆知识点(十六)lambda表达式
开发语言·python
小梁努力敲代码2 小时前
Java多线程--单例模式
java·开发语言
Percep_gan2 小时前
解决-bash: /usr/bin/yum: No such file or directory
开发语言·bash
缺点内向2 小时前
如何在 C# 中将 Word 文档转换为 EMF(增强型图元文件)
开发语言·c#·word·.net
老华带你飞2 小时前
学生宿舍管理|基于java + vue学生宿舍管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
Filotimo_2 小时前
在java后端开发中,redis的用处
java·开发语言·redis
wljun7393 小时前
六、OrcaSlicer 切片之区域
算法·切片软件 orcaslicer
superman超哥3 小时前
仓颉Option类型的空安全处理深度解析
c语言·开发语言·c++·python·仓颉