Created
August 31, 2012 04:31
-
-
Save mbohun/3549091 to your computer and use it in GitHub Desktop.
test_cpp_string_tokenize-00.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iterator> | |
#include <set> | |
#include <sstream> | |
#include <string> | |
namespace { | |
const std::string text("lonely lovely baboon sat on his ass an he was a very lovely but lonely too most likely the loveliest baboon though his ass wasn't lovely really"); | |
template<typename T> | |
std::ostream& operator<<(std::ostream& out, const std::set<T>& s) { | |
std::copy(s.begin(), | |
s.end(), | |
std::ostream_iterator<T>(out, " ")); | |
return out; | |
} | |
} | |
int main(int argc, char* argv[]) { | |
std::cout << "<input>" << text << "</input>" << std::endl; | |
std::istringstream in(text); | |
std::set<std::string> uniq; | |
for(std::string s; | |
std::getline(in, s, ' '); | |
uniq.insert(s)); | |
std::cout << "<output>" << uniq << "</output>" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment