#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
string fileName="F:\\test.txt";
size_t intPos=fileName.find_first_of("test");
string str=fileName.substr(0,intPos);
string strWillReplace="test";
string strWillReplaced="Dingjun";
string strWillReplaceEnter="enter";
size_t strEnterLen=strWillReplaceEnter.length();
size_t intTestLength=strWillReplace.length();
size_t intLength=strWillReplaceEnter.length();
string strReplace=fileName.replace(intPos,intTestLength,strWillReplaced);
ifstream in(fileName.c_str());
//ifstream in("test.txt");
string strWord;
const int maxLineNumber=100;
char buffSize[maxLineNumber];
//while(in.getline(buffSize,99))
//while(in >>strWord)
ofstream out("newTest.txt");
while(getline(in,strWord))
{
//cout<<"Read from file test.text "<<buffSize<<endl;
size_t strPosition=strWord.find("enter",0);
if(strPosition!=-1)
{
strWord=strWord.replace(strPosition,intLength,strWillReplaced);
}
//int strPositionNoFind=strWord.find("enter1",0);
//out>>strWord;
//int post=strWord.find("enter1",0);
cout<<"Read from file test.text "<<strWord<<endl;
out<<strWord<<endl;
}
out.close();
//for(int i=1;i<1000;i++)
cout<<"Hello World"<<endl;
//in>>Pause;
}
#include <fstream>
#include <string>
using namespace std;
void main()
{
string fileName="F:\\test.txt";
size_t intPos=fileName.find_first_of("test");
string str=fileName.substr(0,intPos);
string strWillReplace="test";
string strWillReplaced="Dingjun";
string strWillReplaceEnter="enter";
size_t strEnterLen=strWillReplaceEnter.length();
size_t intTestLength=strWillReplace.length();
size_t intLength=strWillReplaceEnter.length();
string strReplace=fileName.replace(intPos,intTestLength,strWillReplaced);
ifstream in(fileName.c_str());
//ifstream in("test.txt");
string strWord;
const int maxLineNumber=100;
char buffSize[maxLineNumber];
//while(in.getline(buffSize,99))
//while(in >>strWord)
ofstream out("newTest.txt");
while(getline(in,strWord))
{
//cout<<"Read from file test.text "<<buffSize<<endl;
size_t strPosition=strWord.find("enter",0);
if(strPosition!=-1)
{
strWord=strWord.replace(strPosition,intLength,strWillReplaced);
}
//int strPositionNoFind=strWord.find("enter1",0);
//out>>strWord;
//int post=strWord.find("enter1",0);
cout<<"Read from file test.text "<<strWord<<endl;
out<<strWord<<endl;
}
out.close();
//for(int i=1;i<1000;i++)
cout<<"Hello World"<<endl;
//in>>Pause;
}
梦想与现实的落差,就是我们离成功的距离~