hi::
i back with small problem and i wish to help me.
i have problem with getline()
i search about the solution and i find it but the problem is still
see the example
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#include<ctype.h>
void validate_name(string &name)//validate_name for each student
{
int i;
for(i=0;i<(name.length());i++)
{
while( !(isalpha(name[i])) && !(isspace(name[i])) )
{
cout<<"Enter correct Name of student ,please:\n";
getline(cin,name);
i=0;
}
}
}
class student
{
private:
string name;
public:
student(string N)
{
set_name(N);
}
void set_name(string n)
{
validate_name(n);
name=n;
}
void print()
{
cout<<name;
}
};
int main()
{
string name;
int d,m,y;
cout<<"Enter name ,please\n";
getline(cin,name);
cout<<"Enter the date\n";
cin>>d>>m>>y;
student s1(name);
s1.print();
cout<<d<<" "<<m<<" "<<y;
return 0;
}
---------------------------------
The out put
Enter name ,please
123//incorrcet name
Enter the date
1
2
2000
Enter correct Name of student ,please: // i can not write here the name to correct it ,it go out loop without checked and the function print is invoked
1 2 2000
-----------------------------
see the cooments in the output that describe the problem
i hope see the solution and explaination to complet my projct
Thank you and good luck...