fig21_05.cpp
来自「经典vc教程的例子程序」· C++ 代码 · 共 50 行
CPP
50 行
// Fig. 21.5: fig21_05.cpp
// Demonstrating namespaces.
#include <iostream>
using namespace std; // use std namespace
int myInt = 98; // global variable
namespace Example {
const double PI = 3.14159;
const double E = 2.71828;
int myInt = 8;
void printValues();
namespace Inner { // nested namespace
enum Years { FISCAL1 = 1990, FISCAL2, FISCAL3 };
}
}
namespace { // unnamed namespace
double d = 88.22;
}
int main()
{
// output value d of unnamed namespace
cout << "d = " << d;
// output global variable
cout << "\n(global) myInt = " << myInt;
// output values of Example namespace
cout << "\nPI = " << Example::PI << "\nE = "
<< Example::E << "\nmyInt = "
<< Example::myInt << "\nFISCAL3 = "
<< Example::Inner::FISCAL3 << endl;
Example::printValues(); // invoke printValues function
return 0;
}
void Example::printValues()
{
cout << "\n\nIn printValues:\n" << "myInt = "
<< myInt << "\nPI = " << PI << "\nE = "
<< E << "\nd = " << d << "\n(global) myInt = "
<< ::myInt << "\nFISCAL3 = "
<< Inner::FISCAL3 << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?