Advertisement
Guest User

Untitled

a guest
May 4th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #include <iterator>
  4. #include <iostream>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. string dos(const char * s)
  9. {
  10. static char buf[BUFSIZ];
  11. CharToOemA(s, buf);
  12. return string(buf);
  13. }
  14.  
  15. string win(const char * s)
  16. {
  17. static char buf[BUFSIZ];
  18. OemToCharA(s, buf);
  19. return string(buf);
  20. }
  21.  
  22.  
  23.  
  24. int main()
  25. {
  26. string source, replace;
  27. ifstream ifs("1.txt");
  28.  
  29.  
  30. string inputtext(
  31. (istreambuf_iterator<char>(ifs))
  32. , istreambuf_iterator<char>());
  33. cout << dos("Текст с файла:\n\n") << dos(inputtext.c_str()) << endl;
  34.  
  35.  
  36. cout << dos("Что меняем?\n");
  37. cin >> source;
  38. cout << dos("На что меняем?\n");
  39. cin >> replace;
  40.  
  41. replace = win(replace.c_str());
  42. source = win(source.c_str());
  43.  
  44. int it = inputtext.find(source, 0);
  45.  
  46. while (it != string::npos)
  47. {
  48. inputtext.replace(it, source.length(), replace);
  49. it = inputtext.find(source, it);
  50.  
  51. }
  52.  
  53. cout << dos("\n\nИзменененый текст:\n") << dos(inputtext.c_str()) << endl;
  54.  
  55.  
  56. ofstream ofs("2.txt");
  57. ofs << inputtext;
  58. ofs.close();
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement