1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
const int N=255;
void change(string mas[]);
void del (string mas[]);
void insertB (string mas[]);
void insertA (string mas[]);
int main()
{
int ans;
ifstream file("F.txt");
ofstream file2("FF.txt");
file2<<file.rdbuf();
file.close();
file2.close();
do {
string massive[N];
string prom;
ifstream file;
file.open("FF.txt" , ios::in);
int i=0;
while(!file.eof())
{ getline(file, prom);
massive[i]=prom;
i++;}
cout<<"===========MENU==========="<<endl;
cout<<" Make your choise:"<<endl;
cout<<"1.Insert text before n-th row."<<endl;
cout<<"2.Insert text after n-th row."<<endl;
cout<<"3.Change text in the rows from n-th to m-th."<<endl;
cout<<"4.Delete the rows from n-th to m-th."<<endl;
cout<<"5.End of editing."<<endl;
cin>>ans;
switch(ans){
case 1: insertB (massive);break;
case 2: insertA (massive);break;
case 3: change (massive);break;
case 4: del (massive);break;
case 5: exit(1);
}
}
while(ans!=5);
}
void change (string mas[]){
int n,m;
cout<<"Please enter the rows you want to be changed !"<<endl;
cout<<"From :";
cin>>n;
n=n-1;
cout<<endl<<"To :";
cin>>m;
m=m-1;
cin.ignore(INT_MAX, '\n');
for (n ; n<=m ; n++){
cout<<endl<<"Enter text for ("<<n+1<<")row: "<<endl;
getline(cin,mas[n]);
}
ofstream file2("FF.txt",ios::in);
for (int i=0 ; i<=N; i++){
file2<< mas[i]<<endl;
}
}
void del (string mas[])
{
int n,m;
cout<<"Please enter the rows you want to delete "<<endl;
cout<<"From :";
cin>>n;
n=n-1;
cout<<endl<<"To :";
cin>>m;
m=m-1;
for ( n ; n<N-n ; n++)
{
m++;
mas[n]=mas[m];
}
ofstream file2("FF.txt",ios::in);
for (int i=0 ; i<=N; i++){
file2<< mas[i]<<endl;
}
}
void insertB (string mas[])
{
int n;
string swap[N];
for (int i=0 ; i<N ; i++){
swap[i]=mas[i];
}
cout<<"Please enter the row you want to add text before!"<<endl;
cin>>n;
n=n-1;
cout<<"Enter text for the row : ";
cin.ignore(INT_MAX, '\n');
getline (cin, mas[n]);
for ( n ; n<N ; n++){
mas[n+1]=swap[n];
}
ofstream file2("FF.txt",ios::in);
for (int i=0 ; i<=N; i++){
file2<< mas[i]<<endl;
}
}
void insertA (string mas[]) {
int n;
string swap[N];
for (int i=0 ; i<N ; i++){
swap[i]=mas[i];
}
cout<<"Please enter the row you want to add text after!"<<endl;
cin>>n;
cout<<"Enter text for the row : ";
cin.ignore(INT_MAX, '\n');
getline (cin, mas[n]);
for ( n ; n<N-1 ; n++){
mas[n+1]=swap[n];
}
ofstream file2("FF.txt",ios::in);
for (int i=0 ; i<=N; i++){
file2<< mas[i]<<endl;
}
}
|