C++ 存储类
存储类定义 C++ 程序中变量/函数的范围(可见性)和生命周期。这些说明符放置在它们所修饰的类型之前。下面列出 C++ 程序中可用的存储类:
auto
register
static
extern
mutable
thread_local (C++11)
从 C++ 11 开始,auto 关键字不再是 C++ 存储类说明符,且 register 关键字被弃用。
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 #include<iomanip> 5 #include<cmath> 6 using namespace std; 7 int main(int argc, char** argv) { 8 int s=1; 9 double n=1; 10 double t=1; 11 double pi=0; 12 while((fabs(t))>1e-7) 13 { 14 pi=pi+t; 15 n=n+2; 16 s=-s; 17 t=s/n; 18 } 19 pi=pi*4; 20 cout <<"pi="<<setiosflags(ios::fixed)<<setprecision(6)<<pi<<endl; 21 return 0; 22 }