Hi!
I'm doing a basic course at uni and i have an assignment where i have to prompt the user for a file name; find if the file exists, and then propt the user for a word to find in the file, and then a word to replace in the file. I then have to replace the word and output this to a new file.
This is what i have done so far, but im unsure of how to do the find and replace stuff!
All help would be very much appreciated; here's what ive done so far..also i cant use <string> cos i havent covered in class, i can only use <cstring>.
Here's my code:
Code:
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
char file[50];
char string_find [50];
char string_replace[50];
cout << "Enter an input file: " << endl;
cin >> file;
ifstream infile;
infile.open(file);
if(infile.fail())
cout << "File could not be opened" << endl;
else
{
cout << "Enter a string to find: " << endl;
cin >> string_find;
cout << "Enter a string to replace with: " << andl;
cin >> string_replace;
ofstream outfile;
outfile.open(strcat(file,".out"));
outfile << "test";
}
return 0;
}
Your help is very much appreciated! Thanks in advamce, amy