mardi 17 novembre 2020

How to break a loop when "enter" is pressed in C++ while taking input in an integer array

I have this loop, where arr is an integer array.

for(int i=0; i<=counter;i++)
    {
        cin>>arr[i];
    }

I'm giving input like this

2 4 6 7

I want when enter is pressed after 7, just break this loop.


I think it can be done with something like

if(cin.get()=="\n")

But I can't understand how to implement it here in this code.

Aucun commentaire:

Enregistrer un commentaire