taking input

how to scan integers untill user enters a blank line ??
pls help me out guys !
pls share ur code !

Use getline() function in C++

string s;
while (getline(cin, s)) {
    if (s.size() > 0) {
        int n;
    
        stringstream inp(s);
        inp >> n;
    
        // do something with n
    } else {
        break;
    }
}
1 Like

you can do this.

do
{
scanf("%d%c",&x,&s);
}while(s!='\n')

tqq @bradley

@msd_007 check the revision to convert the string to integer