#include<string> #include<cstring>

2023-05-16

C++ strings

string 只能用cin,cout处理,不能 用scanf(),和printf()

transform( s.begin(),s.end(),s.begin(),::tolower );   转换成小写的函数
transform( s.begin(),s.end(),s.begin(),::toupper );  转换成大写的函数 

 sstream

C++继承了c的library

strlen(),strcpy(),strcat(),strcmp()         

特殊字符的输出:::back slash  \

输出   

 

	string str = "\"hello\" world!!";
	cout << str << endl;

  //string input

//string 类型可以直接比较string comparisons

string str,str2;
if(str>str2)
if(str==str2)
if(str<str2)

//下图本是定义的时候,习惯写成了赋值initiallisation

//字符串的赋值assingment

 //交换Swapping strings

        

//string concatention(连接)

 //string length,string indexing and sub-strings

substr(a,b);

第一个参数是起始的坐标,第二个参数个数,从起始的坐标的开始输出

                   

 //string replace,erase,insert and empty strings

 

 erase删除中间或者头上的内容,后面的内容自动向前补齐

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string str = "1234567890";

	str.erase(1, 2);
	cout << str.at(1) << endl;

	return 0;

}

输出是    4

 //插入insert

 //查找

 

//string conversons

vs2019中为了安全使用  _s  这种做法,但并不是所有的都是这样,竞赛中一般都不这样做

 //arrays of strings 

 

        

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

#include<string> #include<cstring> 的相关文章

随机推荐