fstream方式操作文件(格式转换)

以前一直用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();
}



你可能感兴趣的:(fstream方式操作文件(格式转换))