List of all available Websheets
Viewing cpp/sstreams/examples/stringstream_in by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Using an <tt>istringstream</ii>. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; int main() { // CONSTRUCT from a string stringstream storage("Sample text 2parse"); string word1, word2, word3; int num; // EXTRACT from the stringstream storage >> word1 >> word2 >> num >> word3; cout << "Word 1: " << word1 << endl; cout << "Word 2: " << word2 << endl; cout << "Number: " << num << endl; cout << "Word 3: " << word3 << endl; // has a fail() member function like other istreams cout << "Fail? " << boolalpha << storage.fail() << endl; storage >> num; // try to read more cout << "Fail now? " << storage.fail() << endl; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {} ] |
Solution visibility | |
Is example? i.e., just a demo |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.