String stream in C++
Level 4207 keystrokes
Builds a string by writing mixed values into a stringstream, then parses three integers from another stringstream and prints their sum 60.
C++ code
// An in-memory stream that can be written to like cout1stringstream ss;// Numbers are converted to text as they are written2ss << "Age: " << 25 << ", Score: " << 95.5;// str() returns the accumulated text as a string3string result = ss.str();// Print Age: 25, Score: 95.54cout << result << endl;5 // A stream that reads from the given string6stringstream parser("10 20 30");7int a, b, c;// >> reads whitespace-separated numbers: a = 10, b = 20, c = 308parser >> a >> b >> c;// Print the sum 609cout << a + b + c << endl;Output
Age: 25, Score: 95.5 60
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 16;× 8"× 6>× 6,× 3:× 2.× 2(× 2)× 2+× 2