First the stream stream class
Header file # include <sstream>
Its function is the conversion between different types, and the C language fscanf and fprintf role is the same, but more than the C language more convenient and better use.
Very easy to use method
#include <string> #include <sstream> #include <iostream> int main () { std::stringstream stream; std::string result; int i = n; Stream << i; input int Stream stream >> result;//extract the previously inserted int value from stream
The above code converts the string type to int.
!! Note: It has a buffering function during the conversion process, for example, there is a string "Dada fffff"
Entering a string by buffering once through the while loop
Example:
StringStream SS (s); while (SS>>TMP)//Can press a space one output Val.insert (TMP);
The following sets the set container. is a tree. To be able to carry out a heavy sentence, to filter out repeatedly.
Look at this topic: uva1085 Andy's first diction
Test instructions is to give you a bunch of English. Let you read the words inside and not repeat them.
With a set container, very easy
#include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include < Ctype.h> #include <set>using namespace std;set<string> val;int main () { string s,tmp; while (Cin>>s) { if (s== ' break ') break ; for (int i=0;i<s.size (); i++) { if (Isalpha (S[i])) S[i]=tolower (S[i]); else s[i]= '; } StringStream SS (s); while (SS>>TMP)//Can press a space one output Val.insert (TMP); } For (Set<string>::iterator It=val.begin (); It!=val.end (); it++) cout<<*it<<endl; return 0;}
C++stl set container and Stream class