新手小白,就是这个int x=stoi(s)加上去解决方案生成成功,但无法执行
#include <iostream>
#include <string>
using namespace std;
int main() {
//创建字符串
string s { "Hello" };
//clear
s.clear();
//用数组为字符串赋值
char arr[]{ 'W','o','r','l','d' ,'\0'};//此处没有添加零终止符会乱码
s += arr;
//assign()
s.assign("Hello,World!");
//append
s.append(" ");
s.append(5, '\t');
//s.append("mark");
cout << s << endl;
//insert 空白
s.insert(0, " ");
//移除字串前面的空白
s.erase(0, s.find_first_not_of(" \t\n\r"));//有个空格
//移除后面空白
s.erase(s.find_last_not_of(" \t\n\r")+1);
//把字串转化为整数或浮点数
int x = stoi(s);
cout << s << endl;
cout << x << endl;
return (0);
}