Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Replace the text numbers string in a txt file using C++.. Help Me..

$
0
0

Read a Document and replace the text numbers in a txt file using c++..

For ex: 
Before Document: 
hai hello my daily salary is two thousand and five and your salary is five billion. my age is 
twenty-five. 


After Document: 
hai hello my daily salary is # and your salary is #. my age is #. 

All the text numbers and i put the # symbol.. 

I am trying this code: 

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 

ifstream myfile_in ("input.txt"); 
ofstream myfile_out ("output.txt");
string line; 

void find_and_replace( string &source, string find, string replace ) { 

size_t j; 

for ( ; (j = source.find( find )) != string::npos ; ) { 
source.replace( j, find.length(), replace ); 
} 

myfile_out << source <<endl; 
cout << source << endl; 
} 

int main () { 

if (myfile_in.is_open()) 
{ 
int i = 0,j; 
//string strcomma ; 
// string strspace ; 

while (! myfile_in.eof() ) 
{ 

getline (myfile_in,line); 

string strcomma= "two"; 
string strspace = "#"; 


find_and_replace( line , strcomma , strspace ); 


i++; 

} 

myfile_in.close(); 

} 

else cout << "Unable to open file(s) "; 

system("PAUSE"); 
return 0; 
} 

Please help me.. Give me the correct code..


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>