以前一直用C的方式操作文件,今天试了一下C++的方式。
#include <string>
#include <fstream>;
using namespace std;
int main()
{
char low=0x81;
char up=0xfe;
string str;
ifstream cin("in.txt");
ofstream fout("out.txt");
while(getline(cin,str))
{
if(str == "") continue;
bool flag=true;
for(int i=0;i<str.size()-1;i++){
if(str[i]>=low&&str[i]<=up){
string temp=str.substr(i,2);
i++;
if(temp=="。"||temp=="?"||temp=="!")
fout<<temp<<endl<<endl;
else fout<<temp<<endl;
}
else{
if(str[i]==','||str[i]=='.')
fout<<endl;
}
}
fout<<endl;
}
cin.close();
fout.close();
}
本文介绍如何使用C++进行文件读写操作,并通过字符范围筛选特定字符序列。
2364

被折叠的 条评论
为什么被折叠?



