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

Posted whalelife

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

以上是关于c++连续读取未知个数的数字的主要内容,如果未能解决你的问题,请参考以下文章

有没有办法读取 C++ 中连续特定行上的数字?

C++ 输入一行未知个数的整数

C++ 基本 While 循环:未知输入和值增量

在 C++ 中的单个输入行中读取整数列表

求助,VB函数的参数个数未知,要如何传递参数

C++数据个数未知情况下的输入方法