Пожалуйста, помогите, у меня проблемы с проверкой адреса электронной почты в этой программе, над которой я работаю.Мои последние две вещи - подтвердить адрес электронной почты для sam@this.com и номер телефона в формате xxx-xxx-xxxx.Вот код:
#include<iostream>
using namespace std;
class contact{
private:
string lname;
string fname;
string address;
string email;
string phonenumber;//bool checkphonenumber(string phonenumber)
public:
void output();
void input();
bool checkemail(string email);
//constructor name has to be the same as class
contact(string contact_lname,//parameters
string contact_fname,
string contact_address,
string contact_phonenumber,
string contact_email ){
lname = contact_lname;
fname = contact_fname;
address = contact_address;
phonenumber = contact_phonenumber;//bool checkphonenumber(string phonenumber)
email = contact_email;
}
contact(){//set all variables to null
lname = "";
fname = "";
address = "";
phonenumber = "";
email = "";
}
//set
void setlname(string contact_lname){lname = contact_lname;}
void setfname(string contact_fname){fname = contact_fname;}
void setAddress(string contact_address){address = contact_address;}
//get
string getlname(){return lname;}
string getfname(){return fname;}
string getaddress(){return address;}
};//end class
//to prevent overload run function outside
void contact::output()
{
cout << "Contact name is: " << fname <<" "<< lname <<endl;
cout << "Address is: " << address << endl;//address is not been filtered
cout << "Email Address is: " << email << endl;
}
bool contact::checkemail(string email) {
for(int a = 0; a < email.size(); a++) {
if(email.at(a) = '@') return true;
}
return false;
}
void contact::input(){
cout<<"enter last name: ";
cin>>lname;
cout<<"enter first name: ";
cin>>fname;
cout<<"Enter address: ";
cin>>address;
cout<<"enter email ";
cin>>email;
while (!checkemail(email)) {
cout << "that is an invalid email address, re-entry email address." ;
cin>>email;
}
cout<<"enter phone number ";
cin>>phonenumber;
}
int main(){
contact c;
c.input();
c.output();
return 0;
}
Это часть кода, с которой у меня возникли проблемы.
Это часть, которая должна подтвердить электронную почту.
bool contact::checkemail(string email) {
for(int a = 0; a < email.size(); a++) {
if(email.at(a) = '@') return true;
}
return false;
}
void contact::input(){
cout<<"enter last name: ";
cin>>lname;
cout<<"enter first name: ";
cin>>fname;
cout<<"Enter address: ";
cin>>address;
cout<<"enter email ";
cin>>email;
while (!checkemail(email)) {
cout << "that is an invalid email address, re-entry email address." ;
cin>>email;
}
}