以前只是利用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];
}
谢谢!
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