I am writing a program for a competition that uses "standard stdin procedures" using C++. the first line that is taken in indicates how many lines (x) there are to be expected as input from then on. These lines of input can be strings, integers, or some combination of the two, and every line contains exactly two elements separated by a space. At the moment, I am taking in each line one at a time (handling the info before asking for the next line) in a manner similar to this:
string initial;
getline (cin,initial);
istringstream stringStream (initial);
vector<string> parsedString;
vector<int> data;
char splitToken = ' ';
while ( !stringStream.eof() )
{
string subString;
getline( stringStream, subString, splitToken);
parsedString.push_back( subString );
}
for (int i = 0; i <parsedString.size(); i++)
{
string temp = parsedString[i];
int intTemp = atoi(temp.c_str());
data.push_back(intTemp);
}
unsigned int n = data[0];
unsigned int m = data[1];
In this specific case I know the incoming data will be two integers, but that is not always the case. I was wondering if there was some way to make my code faster, either by changing my approach (perhaps taking all the input lines at once after knowing how many to expect) or by using better built in C++ functions to split the incoming lines at the space into the two elements that compose them.
Thanks