how to use << in stringstream in c++ code example
Example 1: stringstream tutorial
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main() {
string str("Hello from the dark side");
string tmp;
stringstream str_strm(str);
vector<string> words;
while (str_strm >> tmp) {
words.push_back(tmp);
}
for(int i = 0; i<words.size(); i++)
cout << words[i] << endl;
}
Example 2: stringstream in c++
std::stringstream os;
os << "12345 67.89";
std::string strValue;
os >> strValue;
std::string strValue2;
os >> strValue2;
std::cout << strValue << " - " << strValue2 << std::endl;