string类

The string structure is also a dynamic array that can be used almost like a vector. string类 类型也是一个动态数组,用起来很像 vector ,
经常用的s.substr(pos, length) int pos = s.find('c'),还有+用来拼接两个 string
string a = "hatti";string b = a+a;cout << b << "\n"; // hattihattib[5] = 'v';cout << b << "\n"; // hattivattistring c = b.substr(3,4);cout << c << "\n"; // tivastring c = b.substr(3);cout << c << "\n"; // 这个是什么呢,请实践一下int pos;pos = b.find('a');cout << pos << '\n'; //实践一下pos = b.find('x');cout << pos << '\n'; //实践一下// c_str()string s;cin >> s;char * cstr = new char [s.length()+1];strcpy(cstr, s.c_str());printf("%s\n", cstr);
#include <bits/stdc++.h>using namespace std;char s1[110];string s2;int main(){cin >> s2;strcpy(s1, s2.c_str());printf("%s\n", s1);return 0;}
//Note: 我们需要用到不同的头文件#include <vector>#include <set>#include <queue>//总之,可以用万能头//无特殊情况,后面的练习过程中,你可以一直使用万能头了//前提是,你已经了解了不同头文件的作用。比赛的时候认真看比赛要求是否ban掉万能头//在一些Unix评测环境,万能头不一定好用,不稳定#include <bits/stdc++.h>
