How to read n integers from standard input in C++?
I need to read something like: 5 60 35 42 2 38 6 5 8 300 1500 900 And then save the first line in an array. After calling other functions do the same with the next line, and so on. I try with gets() and then use sscanf() to scan the integers from the string, but I don't know how to read n numbers from a string. I've seen input files like this for competitions before. If speed is more of an issue than error detection, you could use a custom routine. Here's one similar to that I use: void readintline(unsigned int* array, int* size) { char buffer[101]; size=0; char* in=buffer; unsigned int* out