// istream get
#include <iostream>
#include <fstream>
#include<string>
#include<cstring>
//#include<sstream>
using namespace std;
int main () {
char c, str[256];
ifstream is;
cout << "Enter the name of an existing text file: ";
cin.get (str,256);
is.open (str); // open file
ofstream was;
was.open("output.mvw");
string st ("There are two needles in this haystack with needles.");
string str2 ("needle");
size_t found;
// different member versions of find in the same order as above:
found=st.find(str2);
if (found!=string::npos)
cout << "first 'needle' found at: " << int(found) << endl;
// let's replace the first needle:
st.replace(st.find(str2),str2.length(),"preposition");
cout << st << endl;
while (is.good()) // loop while extraction from file is possible
{
c = is.get(); // get character from file
if (is.good())
was << c;
}
is.close(); // close file
was.close();
return 0;
}
But I am not getting output. Means actually even if I am trying with simple program also
like
#include<iostream>
using namespace std;
int main()
{
int i;
cout<<"Enter a number";
cin>>i;
cout<<"The number is "<<i;
return 0;
}
Dear Sir,
I have one input file say following
input.txt
Shridhar Vishvanath Suryawanshi
Radha Mahima Suryawanshi
Now I want an output file say output.txt with the following changes
output.txt
Shridhar Vishvanath Suryawanshi
Radha Shridhar Suryawanshi
So I want to replace and insert Shridhar at the place of Mahima in input.txt file and write it in output file with the changes and as output.txt
I can do above things separately means I can read file and write it as output.txt
Also I can replace word Mahima with Shridhar Separately
But I can't read the word Mahima from input.txt and replace it with Shridhar and write it in output.txt file.
In short I want to find and replace words from a file and write them in output.txt file
Thank u