In your code I cannot see checking of newline. See my code, it seems to work fine. Maybe it is solution which you are looking for.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
    int sum = 0;
    string line;
    while (getline(cin, line))
    {
        stringstream ss(line);
        int tmp;
        if (ss >> tmp)
        {
            sum += tmp;
        }
        else
        {
            break;
        }
    }
    cout << "\nSuma tych liczb to: " << sum << "\n\n";
    return 0;
}
1
solved Keep reading numbers until an empty input