The kernel format: header file Ssstrem defines a Ostingstream class derived from the Ostream class ( There is also a Wostream-based Wostringstream class for wide-character sets) if you create a Ostringstream object, you can write the information to it, which will store it. can use methods that can be used for cout Ostringstream objects You can do the following: ostringstream outstr; double price=380.0; Char* ps = " for a copy of the iso/eic c++ standard"; outstr<<fixed; outstr<< "PLAY&NBSP;ONLY&NBSP;CHF" <<price<<ps<<endl; Case: #include <iostream> #include <sstream> #include <string> using namespace std; int main () { ostringstream outstr; string hdisk; cout << "What ' S the name of your disk?"; getline (Cin, hdisk); int cap; cout << "What" s Its cappacity in gb? "; cin >> cap; outstr << "the hard disk " << hdisk < < " has a capacity of " << cap << " gigabytes.\n"; string result = outstr.str (); cout << result; return 0; The } istingstream class allows the use of istream method families to get istingstream The data in the istingstream object can be initialized with a string object string facts; istingstream instr (Facts); can use the istream method to read data from InStr. int n; int sum=0; while (instr >>n) { sum+=n; } reads the contents of a string using the overloaded >> operator, one word; per read #include <iostream> #include <sstream> #include <string> using namespace std; int main () { &nbSp; string lit= "it was a dark and stormy day,and the full moon glowed brilliantly. "; istingstream instr (lit); string word; while (Instr>>word) { cout<<word<<endl; } return 0; }
C + + kernel formatting