c++连续读取未知个数的数字


#include <iostream>
using namespace std;

int main() {
    int n;
    int a[100];
    int i=0,count=0;
    while(cin>>n){
        a[i] = n;
        count++;
        i++;
        if (getchar() == '\n')  break;
    }
    for(int j=0;j<count;j++){
        cout<<a[j]<<" ";
    }
}

重点是

if (getchar() == '\n')  break;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM