C++ 'Using space as a delimiter' -
i complete beginner in c++, , trying following program:
- read sentence console.
- break sentence words using space character delimiter.
- 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
Post a Comment