What does using namespace std; do?

后端 未结 3 512
旧时难觅i
旧时难觅i 2021-01-29 17:03

What is the matter with this C++ code?

I get an error message saying: that there should be a ; before z, which is not correct. The only part t

3条回答
  •  借酒劲吻你
    2021-01-29 17:21

    What does using namespace std; do?

    It tells the compiler which class/namespace to look in for an identifier. You either use using namespace std; in the beginning of the file or have to place it in front of each function that belongs to it.

    What is the matter with this C++ code?

    The syntax to use std::cout is:

    std::cout << source; 
    

    variable source is inserted with the help of operator << in the std::cout stream which prints it to the standard output, i.e. computer monitor.


    std "labels" a function member of the Standard Library. This is a technique used (among other reasons) to resolve (using the resolution operator ::) members that belong to the Standard Library from (possible) name conflicts with functions with similar(same) names and to reduce a scope of a search. std is called a namespace, so using namespace std; is a bit self explanatory.

提交回复
热议问题