Как мне...как мне написать на этом, и когда текст будет написан, он будет в порядке, а затем найти следующую функцию goto и показать время?
моя проблема заключается в том, как добавить функцию go to в этот текстовый редактор и написать в текстовом редакторе?
а ключевое слово и замена тоже не работают и показывают какие-то ошибки?
#include<iostream> #include<conio.h> #include <fstream> using namespace std; void updatetext(); void addtext(); void search(); void deletefile(); void display(); void update(); void replace(); int main() { char admin; char user; int pass; int realpass=123; cout<<"***Press a for ADMIN or u for USER***"<<endl; cin>> admin; if(admin=='a'){ cout<<"Please enter password :)"<<endl; cin>> pass; if(realpass==pass){ cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; } else { cout<<"enter correct password please :( "<<endl; } } else if(user=='u'){ cout<<"welcome to the function"<<endl; } char letter; cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; cout<<"press 1 for WRITE "<<endl; cout<<"press 2 for UPDATE"<<endl; cout<<"press 3 for DELETE "<<endl; cout<<"press 4 for DISPLAY"<<endl; letter=getche(); cout<<endl; switch (letter) { case '1': { cout<<"press 1 to FIND "<<endl; cout<<"press 2 to FIND NEXT"<<endl; cout<<"press 3 to REPLACE"<<endl; cout<<"press 4 for GO TO"<<endl; cout<<"press 5 for TIME"<<endl; letter=getche(); cout<<endl; switch (letter) { case'1': { search(); cout<< "**FIND function**"<<endl; break; } case'2': { //keyword(); cout<< "**FIND NEXT function**"<<endl; break; } case'3': { //replace(); cout<< "**REPLACE function**"<<endl; break; } case'4': { cout<< "**GO TO function**"<<endl; break; } case'5': { cout<< "**TIME function**"<<endl; break; } } letter=getche(); break; } case'2': { cout<< "***You are in 'UPDATE' function***"<<endl; updatetext(); break; } case'3': { cout<< "***You are in 'DELETE' function***"<<endl; deletefile(); break; } case'4': { cout<<" ***You are in 'DISPLAY' function***"<<endl; display(); break; } } system("pause"); { system("COLOR FC"); printf("Welcome to the color changing application!\n"); printf("Press any key to change the background color!\n"); getch(); system("COLOR 7C"); printf("Now the background color is white and Text Color is light Red\n"); printf("Press any key to exit..."); getch(); } return 0; } void addtext(){ ofstream o; string text,fname; cout<<"enter file name :"<<endl; cin>>fname; o.open("fname"); cout<<"Enter Text For"<<endl; cin>>text; o<<text; o.close(); } void updatetext(){ ofstream o; string newtext; o.open("texteditor"); cout<<"file text editor:"<<endl; cout<<"enter new text for"<<endl; cin>>newtext; o<<newtext; o.close(); } void search(){ string line; string search; ifstream myfile("texteditor"); if(myfile.is_open()) { while(getline(myfile,line)) { cout<<"enter string you want to search"<<endl; cin>>search; if(line==search){ cout<<"line found"; } cout<<line<<endl; cout<<"enter search for text"<<endl; cin>>search; } myfile.close(); } else cout<<"unable to open file"<<endl; } void deletefile(){ if( remove( "texteditor" ) != 0 ) perror( "Error deleting file" ); else puts( "File successfully deleted" ); } /* void keyword(ifstream &FileSearch) { string letters; int position=-1; string line; ifstream readSearch; cout<<"enter search word"; cin>>letter; "\n"; FileSearch.open("texteditor"); if(FileSearch.is_open()) { while(getline(FileSearch,line)) { FileSearch>>line; cout<<line<<endl; position=line.find(letter,position+1); if(position==string); if(FileSearch.eof()) break; cout<<line<<endl; } } cout<<"cant find"<<letters<<endl; } */ void display(){ ofstream o; string newtext; o.open("texteditor"); cout<<"File Text Editor:"<<endl; cin>>newtext; o<<newtext; o.close(); }
include<iostream> #include<conio.h> #include <fstream> using namespace std; void updatetext(); void addtext(); void search(); void deletefile(); void display(); void update(); void replace(); int main() { char admin; char user; int pass; int realpass=123; cout<<"***Press a for ADMIN or u for USER***"<<endl; cin>> admin; if(admin=='a'){ cout<<"Please enter password :)"<<endl; cin>> pass; if(realpass==pass){ cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; } else { cout<<"enter correct password please :( "<<endl; } } else if(user=='u'){ cout<<"welcome to the function"<<endl; } char letter; cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; cout<<"press 1 for WRITE "<<endl; cout<<"press 2 for UPDATE"<<endl; cout<<"press 3 for DELETE "<<endl; cout<<"press 4 for DISPLAY"<<endl; letter=getche(); cout<<endl; switch (letter) { case '1': { cout<<"press 1 to FIND "<<endl; cout<<"press 2 to FIND NEXT"<<endl; cout<<"press 3 to REPLACE"<<endl; cout<<"press 4 for GO TO"<<endl; cout<<"press 5 for TIME"<<endl; letter=getche(); cout<<endl; switch (letter) { case'1': { search(); cout<< "**FIND function**"<<endl; break; } case'2': { //keyword(); cout<< "**FIND NEXT function**"<<endl; break; } case'3': { //replace(); cout<< "**REPLACE function**"<<endl; break; } case'4': { cout<< "**GO TO function**"<<endl; break; } case'5': { cout<< "**TIME function**"<<endl; break; } } letter=getche(); break; } case'2': { cout<< "***You are in 'UPDATE' function***"<<endl; updatetext(); break; } case'3': { cout<< "***You are in 'DELETE' function***"<<endl; deletefile(); break; } case'4': { cout<<" ***You are in 'DISPLAY' function***"<<endl; display(); break; } } system("pause"); { system("COLOR FC"); printf("Welcome to the color changing application!\n"); printf("Press any key to change the background color!\n"); getch(); system("COLOR 7C"); printf("Now the background color is white and Text Color is light Red\n"); printf("Press any key to exit..."); getch(); } return 0; } void addtext(){ ofstream o; string text,fname; cout<<"enter file name :"<<endl; cin>>fname; o.open("fname"); cout<<"Enter Text For"<<endl; cin>>text; o<<text; o.close(); } void updatetext(){ ofstream o; string newtext; o.open("texteditor"); cout<<"file text editor:"<<endl; cout<<"enter new text for"<<endl; cin>>newtext; o<<newtext; o.close(); } void search(){ string line; string search; ifstream myfile("texteditor"); if(myfile.is_open()) { while(getline(myfile,line)) { cout<<"enter string you want to search"<<endl; cin>>search; if(line==search){ cout<<"line found"; } cout<<line<<endl; cout<<"enter search for text"<<endl; cin>>search; } myfile.close(); } else cout<<"unable to open file"<<endl; } void deletefile(){ if( remove( "texteditor" ) != 0 ) perror( "Error deleting file" ); else puts( "File successfully deleted" ); } /* void keyword(ifstream &FileSearch) { string letters; int position=-1; string line; ifstream readSearch; cout<<"enter search word"; cin>>letter; "\n"; FileSearch.open("texteditor"); if(FileSearch.is_open()) { while(getline(FileSearch,line)) { FileSearch>>line; cout<<line<<endl; position=line.find(letter,position+1); if(position==string); if(FileSearch.eof()) break; cout<<line<<endl; } } cout<<"cant find"<<letters<<endl; } */ void display(){ ofstream o; string newtext; o.open("texteditor"); cout<<"File Text Editor:"<<endl; cin>>newtext; o<<newtext; o.close(); }
Что я уже пробовал:
Я попробовал это сделать...
#include<iostream> #include<conio.h> #include <fstream> using namespace std; void updatetext(); void addtext(); void search(); void deletefile(); void display(); void update(); void replace(); int main() { char admin; char user; int pass; int realpass=123; cout<<"***Press a for ADMIN or u for USER***"<<endl; cin>> admin; if(admin=='a'){ cout<<"Please enter password :)"<<endl; cin>> pass; if(realpass==pass){ cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; } else { cout<<"enter correct password please :( "<<endl; } } else if(user=='u'){ cout<<"welcome to the function"<<endl; } char letter; cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl; cout<<"press 1 for WRITE "<<endl; cout<<"press 2 for UPDATE"<<endl; cout<<"press 3 for DELETE "<<endl; cout<<"press 4 for DISPLAY"<<endl; letter=getche(); cout<<endl; switch (letter) { case '1': { cout<<"press 1 to FIND "<<endl; cout<<"press 2 to FIND NEXT"<<endl; cout<<"press 3 to REPLACE"<<endl; cout<<"press 4 for GO TO"<<endl; cout<<"press 5 for TIME"<<endl; letter=getche(); cout<<endl; switch (letter) { case'1': { search(); cout<< "**FIND function**"<<endl; break; } case'2': { //keyword(); cout<< "**FIND NEXT function**"<<endl; break; } case'3': { //replace(); cout<< "**REPLACE function**"<<endl; break; } case'4': { cout<< "**GO TO function**"<<endl; break; } case'5': { cout<< "**TIME function**"<<endl; break; } } letter=getche(); break; } case'2': { cout<< "***You are in 'UPDATE' function***"<<endl; updatetext(); break; } case'3': { cout<< "***You are in 'DELETE' function***"<<endl; deletefile(); break; } case'4': { cout<<" ***You are in 'DISPLAY' function***"<<endl; display(); break; } } system("pause"); { system("COLOR FC"); printf("Welcome to the color changing application!\n"); printf("Press any key to change the background color!\n"); getch(); system("COLOR 7C"); printf("Now the background color is white and Text Color is light Red\n"); printf("Press any key to exit..."); getch(); } return 0; } void addtext(){ ofstream o; string text,fname; cout<<"enter file name :"<<endl; cin>>fname; o.open("fname"); cout<<"Enter Text For"<<endl; cin>>text; o<<text; o.close(); } void updatetext(){ ofstream o; string newtext; o.open("texteditor"); cout<<"file text editor:"<<endl; cout<<"enter new text for"<<endl; cin>>newtext; o<<newtext; o.close(); } void search(){ string line; string search; ifstream myfile("texteditor"); if(myfile.is_open()) { while(getline(myfile,line)) { cout<<"enter string you want to search"<<endl; cin>>search; if(line==search){ cout<<"line found"; } cout<<line<<endl; cout<<"enter search for text"<<endl; cin>>search; } myfile.close(); } else cout<<"unable to open file"<<endl; } void deletefile(){ if( remove( "texteditor" ) != 0 ) perror( "Error deleting file" ); else puts( "File successfully deleted" ); } /* void keyword(ifstream &FileSearch) { string letters; int position=-1; string line; ifstream readSearch; cout<<"enter search word"; cin>>letter; "\n"; FileSearch.open("texteditor"); if(FileSearch.is_open()) { while(getline(FileSearch,line)) { FileSearch>>line; cout<<line<<endl; position=line.find(letter,position+1); if(position==string); if(FileSearch.eof()) break; cout<<line<<endl; } } cout<<"cant find"<<letters<<endl; } */ void display(){ ofstream o; string newtext; o.open("texteditor"); cout<<"File Text Editor:"<<endl; cin>>newtext; o<<newtext; o.close(); }
Richard MacCutchan
Нет никакого смысла просто сбрасывать груз кода без какого-либо объяснения того, в чем заключается ваша проблема или где она возникает. Пожалуйста, отредактируйте свой вопрос и добавьте некоторые правильные детали.