I am creating a texteditor in c++[non gui] , So far i have ended up with this code..
i get two undeclared errors… Why?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int op;
cout<<"do you want to open example.txt or overwrite?\nIf you want to overwrite enter 1 , if you want to view it enter 2. :\n";
cin>>op;
if(op==1)
{
edit();
}
else if(op==2)
{
open();
}
}
void edit()
{
int op;
string x;
ofstream a_file("example.txt" , ios::app);
cout<<"HEY ENTER SOME TEXT TO BE WRITTEN TO EXAMPLE.txt [created by rohan bojja]\n--------------------------------------------------------------------------------\n";
getline ( cin , x);
a_file<<x;
cout<<"want to type in an other line?\n1 for YES, 2 for NO";
cin>>op;
while(op==1)
{
a_file<<"\n";
edit;
}
cout<<"Do you want to quit?\n1 for YES , 2 for NO";
cin>>op;
if (op==2)
{
edit;
}
}
void open()
{
int op;
ifstream a_file("example.txt");
cout<<"You are now viewing example.txt [created by rohan bojja]\n--------------------------------------------------------------------------------\n";
cout<<a_file;
cout<<"Do you want to quit?\n1 for YES , 2 for NO";
cin>>op;
if(op==2)
{
open;
}
}
but , while compiling i get the error [CodeBlocks Build Log]:
F:\Projects\c++\TextEditor\texteditor.cpp: In function 'int main()':
F:\Projects\c++\TextEditor\texteditor.cpp:14: error: 'edit' was not declared in this scope
F:\Projects\c++\TextEditor\texteditor.cpp:18: error: 'open' was not declared in this scope
Your main function can’t see the edit and open functions because they appears after main. You can fix this by either:
1) Moving the edit and open functions above main; or
2) Adding a prototype of edit and open above main. Add this line of code before main, but after using namespace std: