can you please help me, i want to know about clear(), what is its use; what happen if not use this method in this program. I only know about clear() is that, it is used to clear error flags.
#include<iostream>
#include<fstream>
#include<stdio.h>
using namespace std;
void add()
{
    char name[21];
    ofstream k("friends.frn", ios::app);
    cout << "Enter your name : ";
    cin.getline(name, 21);
    cin.clear();
    fflush(stdin);
    k << name;
    k << '\n';
}
int main()
{
    int ch;
    while (1)
    {
        cout << "1. Add"; << endl;
        cout << "2. Exit"; << endl;
        cout << "Enter your choice : ";
        cin >> ch;
        cin.clear();
        fflush(stdin);
        if (ch == 1) add();
        if (ch == 2) break;
    }
    return 0;
}
 
    