dimanche 17 mai 2020

How I can handle with error about entered size of string exceeds the set size of char array?

I need some kind of error handler if I enter a string larger than the set size.

cout << "Enter long of the string" << endl;
        cin >> N;
        char* st = new char[N];
        char* st1 = new char[N];
        for (int i = 0; i < N; ++i) {
            *(st1 + i) = ' ';
        }
        cout << "Enter string in the end put 0,without whitespace in the end." << endl;
        cin.getline(st, N, '0');

Aucun commentaire:

Enregistrer un commentaire