How would I be able to search for a number and change it in a text file?
I looked through many sites and this forum and have not yet found something useful.
For example:
file content:
12 dogs bark at the moon at 9
Lets say some bad weather happened so the dog delays its barking by 2 hours.
So now the text file should say
thanks!, I managed to do it some way but I can't figure out why it won't output to texfile but even then how I would I be able to replace the line with the intended output?
if (find(ids.begin(), ids.end(), newid) != ids.end())//Since the original line was stored in a vector i was able to use this to see if the input ID matches the file
{
fstream edit;//opens file
edit.open("books.txt");
if (!edit)
{cout<<"Error opening file"<<endl;
}
cout<<"This book already exists"<<endl;
unsignedint curLine = 0;
string line;
string search;
cout<<"Enter ID again"<<endl;
cin>>search;
//Gets line number which corresponds to the vector cell and i was able to update the copies of the books of the line
while(getline(edit, line)) { // I changed this, see below
curLine++;
if (line.find(search) != string::npos) {
cout << "found: " << search << "line: " << curLine << endl;
copy[curLine-1]=copy[curLine-1]+1;
cout<<copy[curLine-1];
edit.clear();
edit<<ids[curLine-1]<<titles[curLine-1]<<authors[curLine-1]<<cat[curLine-1]
<<copy[curLine-1];//This is the troublesome part won't output to texfile no changes were made to the file and I want this to replace the line
}