C/C++语法、库的使用

文件操作

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
	ifstream fin("in.txt");
	char c;
	fin>>c;
	cout<<c;
	fin.close(); 
	return 0;
}
 

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	freopen("in.txt","r",stdin);
	char c;
	cin>>c;
	cout<<c; 
	fclose(stdin);
	return 0;
}
 
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	FILE * fin;
	fin=fopen("in.txt","rb");
	//fin=stdin;
	char c;
	fscanf(fin,"%c",&c);
	cout<<c; 
	fclose(stdin);
	return 0;
}
 

string.find()
https://www.cnblogs.com/wkfvawl/p/9429128.html

s.find(str);返回第一个起始下标
s.rfind(str);从右边找,返回右边第一个子串位置的起始下标
s.find_first_of(str);返回第一个起始下标 ==s.find()
s.find_last_of(str);返回最后一个子串的末尾字符下标
	string s="0123456789";
	cout<<s.find("789")//7
	cout<<s.rfind("789")//7
	cout<<s.find_first_of("789");//7
	cout<<s.find_last_of("789");//9
string.replace
s1.replace(s1.find(s2),s2.size(),"",0,0);
s.replace(0,1,"abc",0,2);
s.replace(0,1,"abc");
5个参数:s1开始下标 s1被替换的长度  s2  s2开始下标  s2的去替换的长度
string.substr
s1.substr(2, 4);//s1下标从2开始的4个字符长度的子串
s1.substr(2);//s1下标从2开始到末尾的子串
string.erase
s1.erase(1, 3);//删除s1下标1开始的3个字符
s1.erase(1);//删除s1下标1开始到末尾
string.insert
s1.insert(3, s2);  //在下标 2 处插入 s2 
s1.insert(3, 5, 'X');注意插入的是字符了
STL::find()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wow_awsl_qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值