typeof
/*
* File Name: test_typeof.cpp
* Operating Environment: ubuntu linux
* Author: Jiang
* Email: ligelaige@gmail.com
* Created Time: 2014年04月25日 星期五 18时26分58秒
*/
#include <iostream>
using namespace std;
void out_line(int n = 0, string outstr = "-")
{
for (int i = 0; i < n; ++i)
{
cout << outstr;
}
cout << endl;
}
int main (int argc, char const* argv[])
{
int f1 = 0;
typeof(f1) f2 = 1;
typeof(f1) f = f1 + f2;
for (int i = 0; i < 10; ++i)
{
f = f1 + f2;
f1 = f2;
f2 = f;
out_line(f, "*");
}
return 0;
}
编译与运行:
➜ 25.4.2014 g++ test_typeof.cpp
➜ 25.4.2014 ./a.out
*
**
***
*****
********
*************
*********************
**********************************
*******************************************************
************************************
C++中的typeof与auto关键字解析

本文探讨了C++编程中typeof和auto关键字的使用,重点在于它们在类型推断上的差异。typeof允许程序员获取表达式的静态类型,而auto则作为C++11引入的类型推断机制,简化了变量声明。文章详细解释了两者的工作原理,并通过实例展示了如何在实践中应用。
最低0.47元/天 解锁文章
1698

被折叠的 条评论
为什么被折叠?



