So i have this code to ask a user input which is numbers and put it to vector and i succesfully do it BUT when a user accidentally put a letter on it or any character it will go for a infinite for loop just a beginner :(
#include <iostream>
#include <vector>
using namespace std;
int main(){
char letter{};
int howmany {};
vector <int> vector {};
cout << "How many elements inside list? ";
cin >> many;
for (int i{1}; i <= howmany;i++){
int arr {};
cout << "Please enter number"<<endl;
cin >> arr;
vector.push_back(arr);
Aucun commentaire:
Enregistrer un commentaire