0

I wanted to code something for write to fstream but my void function works fist what I wanted but next after used do while statement it doesn't do what did before it skips the name input then goes to output with puts(), even cout can't solve it how do i solve and any advice on tools i am using i appreciate your time to read this Code :

class student
{
    public:
        void ask()
        {
            std::cout<<"Hello Sir whats your name"<<std::endl;
            gets(name);
            std::cout<<"What do you like"<<std::endl;
            gets(item);
            std::cout<<"How old are you"<<std::endl;
            gets(age);
            std::cout<<"Done..."<<std::endl;
        }
    private:
        char name[20];
        char item[20];
        char age[4];
};
int main()
{
    student st1;
    char c[6];
    char g[10];
    char yes;
    do
    {
        st1.ask();
        std::cout<<"again...?"<<std::endl;
        std::cin>>yes;
    
        
    }
    while(yes=='Y' || yes=='y');
    
    
    
    return 0;
}
Fate8086
  • 3
  • 3
  • `gets()` is [much worse](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) than `getline()`, but it's also an example of unformatted extraction, as opposed to formatted extraction with `std::cin >>` – Yksisarvinen Nov 16 '20 at 11:58
  • Which C++ textbook taught you to use `gets()` in C++ code? Where did you learn to do that? – Sam Varshavchik Nov 16 '20 at 12:06

0 Answers0