Contains header files #include <sstream>
Initialization can be assigned using clear (), str ();
can use << input and >> output
String S;stringstream ss;int A, B, C;getline (CIN, s); Ss.clear (); Ss.str (s); SS >> a >> b >> c; The default space here is a direct word, and even if the type of ABC is different, it is equivalent to flexible type conversion
String S;stringstream ss;int N, I, Sum, a;cin >> n;getline (CIN, s); Read line break for (i=0; i<n; i++) { getline (CIN, s); Ss.clear (); SS.STR (s); sum=0; while (1) { ss >> A; if (Ss.fail ()) break; Fail () to determine if the sum+=a is in the end ; } cout << sum << Endl;}
StringStream is convenient for split . String A, B, C, D; String lines= "ADFA;ASDFASD;FASDF;CCC"; StringStream line (lines); Getline can be initialized directly (line, A, ' f '); Getline (line, B, '; '); Getline (line, C, '; '); Getline (line, d); Paired with different getline cout<< "a =" <<a<<endl; cout<< "b =" <<b<<endl; cout<< "c =" <<c<<endl; cout<< "D =" <<d<<endl;
There is another problem: the default participle here is a space, then if it is other such as comma how to do
Examples of StringStream in C + +