//string::find
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <string.h>
#include <iomanip.h>
usingnamespace std;
class Ticket
{protected:
int type;
string number;
public:
Ticket(){ cout<< "enter number"<<endl; cin>>number; }
void set_number() {cout<<" enter the number of winning ticket"<<endl;
cin>>number;
} // end of set_type
string get_number(){return number;} // end of get_type
};
class Lottery:public Ticket
{
string a[35];
public:
Lottery(){ifstream read("win.txt", ios::in);
for(int i=1; i<36;i++)
{read>>a[i];
cout<<a[i]<<endl;
}
} // end of lottery constructor
void search(){
for(int i=1; i<36; i++)
{if(a[i]==number)
{cout<<"you won"<<endl;
throw Ex(number);}
}
} // end of search function
};
Ex{
string j;
public:
Ex(string m){ j=m; }
void print() { cout<<j<<" sehryer is okey" };
};
int main()
{
Lottery lucky;
try
{
lucky.search();
}
catch (Ex &x)
{
x.print();
};
system("pause");
return 0;
} // end of main;
ı did not understand why this code is not working, because when ı throw normal string it is okey. However, when ı want to throw exceptional class, it shows to me undeclared exceptional class..
What kind of an object is Ex? The compiler does not know, because it has never seen that kind of an object. In C++, the compiler must know about an object before you try to use it.
Ex{
If this is meant to be defining the class Ex, you need to use the class keyword. class Ex{