I am trying to write a program in which a big text file is read and then user searches for a word and replaces it with another word. To implement this I was thinking to store the file read into an array since that would the easiest way to implement it (as far as I Know) and then compare each element with the word to be searched and when found replace it.
Here is my code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream insert;
ofstream output;
string lineread;
insert.open("test.txt");
if(insert.fail())
{
cout<<"File failed to open"<<endl;
}
while(!insert.eof())
{
getline(insert,lineread);
cout<<lineread<<endl;//test to see if it prints the right text file
}
system("PAUSE");
return (0);
As you can see I have used a string variable to store the file being read but I want it to be stored in array which I don't understand how to implement.
I thought of using pointer arrays or better dynamic arrays but I am not able to implement it. Also I have looked up the pop and stack functions but I haven't been taught that so I am not very sure to use them.
Besides that any help is appreciated