Introduction of C + + iostream standard library

Source: Internet
Author: User
Tags inheritance printf

We've been doing a variety of exercises from the start using C + + input and output, the input output is provided by the iostream library, so it is necessary to discuss this standard library, unlike the Stdio Library of C, which from the outset is an object-oriented hierarchy implemented with multiple inheritance and virtual inheritance. As a standard library component for C + + to be used by programmers.

Iostream provides input and output support for built-in type-type objects, as well as file input and output, and the designer of the class can support the custom type of input-output operations by extending the iostream library.

Why do you want to expand to provide support? Let's take an example.

#include <stdio.h>
#include <iostream>
using namespace Std;
Class Test
{
Public
Test (int a=0,int b=0)
{
Test::a=a;
Test::b=b;
}
int A;
int b;
};
int main ()
{
Test T (100,50);
printf ("%???", t);//Ambiguous output format
scanf ("%???", t);//Ambiguous input format
Cout<<t<<endl;//is also not clear enough
Cin>>t;//is also not clear enough
System ("pause");
}

Because of the specificity of the custom class, in the above code, whether you use C-style input output, or C + + input and output is not an ambiguous representation, because the C language does not have operator overloading mechanism, resulting in the Stdio library is not scalable, so we can not let printf () and scanf () Supports extended recognition of custom class objects, and C + + is the ability to extend iostream libraries through operator overloading mechanisms, allowing the system to recognize custom types so that input and output know exactly what they should do and what format to use.

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.