c++ - Could someone explain why my string stream is not working properly? -


i new string streams & c++ in general. use explanation how construct string stream properly. constructed 1 in code below. code supposed take user input, store in string stream, , add of numbers in stream together. decided comment out "ss >> numinput;" line because when not commented out, skip on adding first integer of stream sum. explain me "ss >> numinput;" means, if need use it, etc. ? know partially how write string streams textbook, confused why it's working improperly in scenario. thank explanations string streams.

#include <iostream> #include <sstream> using namespace std; int main(){   int = 0;   int sum = 0;   string numinput;   cout<<"input 1 or more integers"<<endl;   getline(cin,numinput);   stringstream ss(numinput); //makes new stream string                             //ss >> numinput;   cout<<"your input was: " << numinput<<endl;      while(ss >>  a){       sum += a;       cout<<sum<<endl;     }     cout<<"the sum of integers is: " << sum; } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -