streams
How do you handle whitespace in C++? I'm trying to write a function that will accept up to 4 strings as input.
Thanks.
Are you trying to read from a file or from an interactive console? What kind of strings are you trying to read? Arbitrary strings written by a machine, strings that represent numbers, names, phone numbers?
#include <iostream>#include <sstream>#include <string>int main() { std::cout << "Give me some strings: "; std::string temp; std::getline(std::cin, temp); std::stringstream sstream(temp); std::cout << "Your strings were:\n"; while(sstream >> temp) std::cout << "\t\"" << temp << "\"\n"; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement