输入流 - C++中一行中的数据量过大,怎样完成输入
阿神
阿神 2017-04-17 15:39:19
0
2
656

以前只是利用cin读取简单的几个数据,现在要输入的数据在一行内,大概包含5000个四位数,利用下面的代码后发现输入到七八百个就无法继续输入了,这是cin的问题吗(只能在输入回车键后,才能将数据送入缓冲区)?应该怎么解决这种问题呢?试了cin.getline()cin.get()scanf都没能解决这个问题。

int size;
cin>>size;
double array[size];
for(int i=0;i<size;i++){
    cin>>array[i];
}

谢谢!

阿神
阿神

闭关修行中......

reply all(2)
Ty80

In this case I will choose to read the data from the file

伊谢尔伦

It should not be necessary to enter a newline character before the buffer is flushed. The buffer should be flushed automatically when it is full. If this doesn't work, maybe the poster can change his mind? You first use read or getline (haven't tested it yet), and read all the input in string or char* at once. Then you must use the same delimiter when inputting, assuming it is a space, and then you use For boost's split, input the split according to the space, and then convert the elements in the resulting vector into numbers and it will be ok

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!