C + + kernel formatting

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.