C ++ primer learning note (3.1) namespace using statement

Source: Internet
Author: User

Chapter 3 Standard Library types

3.1TheUsingStatement

In general, the header file should only define the necessary things.

 
# Include <iostream> Using STD: CIN; Using STD: cout; Using STD: Endl; int main () {// some codes .....}

C ++StandardProgramAll identifiers in the library are defined inSTDOfNamespace.

Therefore, it is more convenient to useUsing namespace STD;

For example:

# Include <iostream>

Using namespace STD;

In this way, the namespaceSTDAll identifiers defined in !! You don't have to write them one by one !!

Exercise3.1

//Use appropriateUsingStatement, insteadSTDPrefix: calculates the result of a given power of a given number.

 
# Include <iostream> Using STD: CIN; Using STD: cout; Using STD: Endl; int main () {int Val, pow, Res = 1; cout <"enter two numbers" <Endl; CIN> Val> POW; For (int cnt = 1; CNT <= POW; CNT ++) res = res * val; cout <"the result of" <Val <"^" <POW <"is" <res <Endl; return 0 ;}

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.