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

}

相关推荐
程序员Sunday3 小时前
JavaScript 事件循环面试题,宏任务与微任务怎么执行|Sunday面试指南
开发语言·javascript·面试·校招·事件循环·程序员sunday
zhangzeyuaaa4 小时前
Ruby 多线程、GVL(GIL)与 Mutex 完全指南
开发语言·前端·ruby
weiabc4 小时前
MSYS2 UCRT64 + g++ C++ 中文输出乱码 完整全过程
c++
谢亮_vipxieliang5 小时前
用 PHP 构建轻量级 REST API:从路由到鉴权的完整实践
开发语言·后端·php
思无邪665 小时前
用 AI 做 JS 逆向:从抓包到复现的完整方法论
开发语言·javascript·人工智能
灯澜忆梦6 小时前
【面向对象编程C++】| 基础语法
java·c++·算法
小蒋观天下6 小时前
专项方案:大场景港口AI安防、多干扰环境下的算法调优与落地实操
人工智能·深度学习·算法·安全·机器学习·计算机视觉·ai大模型
Evand J6 小时前
【电机滤波例程5】渐消因子自适应扩展卡尔曼滤波(EKF),MATLAB。PMSM负载突变下的状态估计。附下载链接
算法·matlab
H.莓飛6 小时前
【数据结构】二叉树_OJ题
linux·开发语言·数据结构·算法
好想像大佬一样能够ak所有7 小时前
Leetcode35.搜索插入位置
数据结构·算法·leetcode