c++回车停止输入

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int a[100],i=0;
    int c=0;
    char s;
    while(s!='\n')
    {
        scanf("%d",&a[i]);//输入int
        s=getchar();//接收输入数字后面的字符
        i++;
        c++;
    }
    for(int i=0;i<c;i++)
    {
        printf("%d ",a[i]);
    }
    cout << "Hello, World!\n";
    return 0;
}

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_37486501/article/details/80820057