字符串
字符串的输入输出+其他操作
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
using namespace std;
int main() {
char buf[100];
fgets(buf, 100, stdin);
string str = buf;
str.erase(str.size() - 1);
str.clear();
str = str + "world";
printf("str = %s\n", str.c_str());
}
find查找操作
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
using namespace std;
int main() {
string str = "howareyou";
int pos = str.find("was");
if (pos != string::npos) {
printf("Found, pos = %d\n", pos);
}
else {
printf("Not Found\n");
}
}