Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int find(string& storeText, ifstream& fileIn);
- bool updateHistory(bool& r);
- int main()
- {
- string fileName;
- string storeText;
- bool r = false;
- cout << "What file do you want to open?" << endl;
- cout << "The file you want to open must be typed in EXACTLY as it" << endl;
- cout << "appears on your computer; for example: document.txt" << endl;
- cout << "Enter file name: ";
- getline(cin, fileName);
- if(fileName == "updatehistory")
- {
- updateHistory(r);
- }
- if(r == true)
- {
- cout << "Enter file name: ";
- getline(cin, fileName);
- }
- ifstream fileIn;
- fileIn.open(fileName.c_str());
- cout << "\n";
- if(fileIn.fail())
- {
- cout << "Failed to open" << endl;
- fileIn.close();
- }
- stringstream ss(stringstream::app | stringstream::out);
- while(getline(fileIn, storeText))
- {
- ss << storeText << endl;
- }
- cin.ignore();
- storeText = ss.str();
- find(storeText, fileIn);
- fileIn.close();
- }
- int find(string& storeText, ifstream& fileIn)
- {
- size_t found;
- string str2;
- string str3;
- found = storeText.find(str2);
- cout << storeText << endl;
- if(found == string::npos)
- {
- cout << "Error" << endl;
- return 0;
- }
- cout << "Which word you want to find from the document?: ";
- getline(cin,str2);
- cout << "Enter a word that will replace it: ";
- getline(cin,str3);
- cout << "After replacing with the given word: \n" << endl;
- storeText.replace(storeText.find(str2), str2.length(), str3);
- cout << storeText << endl;
- cin.ignore();
- }
- bool updateHistory(bool& r)
- {
- cout << "VERSION INFORMATION\n" << endl;
- cout << "Version: 1.0.0 Alpha" << endl;
- cout << "Recently added features" << endl;
- cout << "1. Added find and replace function" << endl;
- cout << " However it currently only can do 1 tem at a time" << endl;
- cin.get();
- return r = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement