C++点滴

来源:互联网 发布:婚庆网站源码下载 编辑:程序博客网 时间:2024/06/16 18:52

(×)程序运行时间统计代码

http://stackoverflow.com/questions/876901/calculating-execution-time-in-c

http://stackoverflow.com/questions/2808398/easily-measure-elapsed-time



( × ) 变量类型范围和数的二进制表示

int var_int_min = 0xFFFFFFFF;int var_int_max = 0x7FFFFFFF;cout << "var_int_min: " << var_int_min << endl; //输出-1,why?cout << "var_int_max: " << var_int_max << endl;//cout << "the size of  is: " << sizeof() << endl;cout << "the size of bool is: " << sizeof(bool) << endl;cout << "the size of char is: " << sizeof(char) << endl;cout << "the size of wchar_t is: " << sizeof(wchar_t) << endl;cout << "the size of char16_t is: " << sizeof(char16_t) << endl;cout << "the size of char32_t is: " << sizeof(char32_t) << endl;cout << "the size of short is: " << sizeof(short) << endl;cout << "the size of int is: " << sizeof(int) << endl;cout << "the size of long is: " << sizeof(long) << endl;cout << "the size of long long is: " << sizeof(long long) << endl;cout << "the size of float is: " << sizeof(float) << endl;cout << "the size of double is: " << sizeof(double) << endl;cout << "the size of long double is: " << sizeof(long double) << endl;

输出

var_int_min: -1var_int_max: 2147483647the size of bool is: 1the size of char is: 1the size of wchar_t is: 2the size of char16_t is: 2the size of char32_t is: 4the size of short is: 2the size of int is: 4the size of long is: 4the size of long long is: 8the size of float is: 4the size of double is: 8the size of long double is: 8

How to get the type of a variable or a literal?

source

use typeid operator

#include <typeinfo>...cout << typeid(variable).name() << endl;


extern和include的用法区别???


extern_test.h

int ext = 0;

source.cpp

#include "extern_test.h"#include <iostream>
using namespace std;int main() {cout << ext << endl;return 0;}

两个文件,source只要include.h文件,就能正常使用ext. extern声明在什么情况下用?


0 0