I have to replace a string of a file by first opening it . the code i used is
In the file it is CONVERTED_REC_STATS = 7/or any number. i have to replace it with
CONVERTED_REC_STATS = UNK :7 ie i have to insert UNK in between CONVERTED_REC_STATS = and the number.so i have used this code..
#include<stdio.h>
#include <iostream>
#include <fstream>
#define T 8192
using namespace std;
char text[T];
int main()
{
string strReplace = "CONVERTED_REC_STATS";
string strNew = "CONVERTED_REC_STATS = UNK :";
string strReplace1 = "REC_KEY,ORIG_REC_KEY";
string strNew1 = " ""REC_KEY"",""ORIG_REC_KEY"" ";
std::ifstream filein("SKJ12032012.00112"); //File to read from
std:fstream fileout("write2.txt"); //Temporary file
if(!filein || !fileout)
{
cout << "Error opening files!" << endl;
return 1;
}
First you code is very hard to read/understand. The reason is you didn't use Code tags.
Second, why do you use strncmp C-runtime to work with the std::string rather than using std::string::replace method?
In the file it is CONVERTED_REC_STATS = 7/or any number. i have to replace it with
CONVERTED_REC_STATS = UNK :7 ie i have to insert UNK in between CONVERTED_REC_STATS = and the number.
If you only need to do this once, you could just use a text editor.
Bookmarks