The way your current code is setup does not match what you told us. What you're doing is inputting the values one at a time. You stated that the numbers needed to be in one line. Are you reading the numbers from a external file or from the terminal?
std::string inputLine;
getline(cin, line);
// Now read the characters. Each time you get to a space, turn the characters you read into a number,
// add them to the sum, and then carry on
I think the best way would be to use stringstream. Pass the string you got from getline to the stringstream constructor. Then just use operator >> until the stream is empty.