C++ 'Using space as a delimiter' -


i complete beginner in c++, , trying following program:


  1. read sentence console.
  2. break sentence words using space character delimiter.
  3. iterate on each word, if word numeric value print value doubled, otherwise print out word, each output on own line.

i lost on how this. using space key delimiter.

can have following :

with std::stringstream , std::getline

std::string str; std::string temp; std::getline(std::cin,str);  std::stringstream ss(str);  while(getline(ss,temp, ' ')) // delimiter space {       std::stringstream stream(temp);       if(stream >> val)         std::cout<<2*val<<std::endl;       else          std::cout<<temp<<std::endl; } 

see demo


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -