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

}

相关推荐
LDR0065 小时前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术5 小时前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
通信小呆呆5 小时前
当算法有了“五感”:多模态数据融合如何向人体感官协同学习?
人工智能·学习·算法·机器学习·机器人
码云数智-园园5 小时前
C++20 Modules 模块详解
java·开发语言·spring
benben0445 小时前
强化学习之DQN算法族(基于gymnasium开发)
算法
swordbob6 小时前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享6 小时前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.6 小时前
C语言--day30
c语言·开发语言
玖玥拾6 小时前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器