stringstream with escape characters
I've been trying to incorporate escape characters into stringstream, but I cannot figure out how to implement this correctly for the life of me. At the moment, I cannot even compile the program because of an "unknown escape sequence" error.
Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using std::string;
int main(void) {
std::vector<string> tokens;
string str("This sentence \t should be split up into individual words except for this\ one");
string buf;
std::stringstream ss(str);
while (ss >> buf)
tokens.push_back(buf);
for (int i = 0; i < tokens.size(); i++) {
std::cout << tokens[i] << std::endl;
}
}
Ideally, the output should be:
This
sentence
should
be
split
up
into
individual
words
except
for
this one
Any assistance would be greatly appreciated.