1、关于初始化:
deque<string> Deque;// 一个deque容器

deque<string> Deque2(Deque.begin(),Deque.end()); // 一种初始化

copy(Deque.begin(),Deque.end(),back_inserter(Deque2) ); // 一种初始化

deque<string> Deque3(istream_iterator<string>(cin),istream_iterator<string>()); // 一种初始化

现在讨论第三种初始化方式,
typedef istream_iteraor<string> (Func)();

deque<string> Deque3(istream_iteraotr<string> cin, Func);
看上去像一个函数声明,

typedef istream_iteraor<string> (Func)();
deque<string> f(stream_iteraor<string> ,Func);
现在比较清晰了吧,很像一个函数声明了,

所以第三种初始化方式根本就不能做任何事情.

//如果真的要达到初始化的目标,可以通过括号来消除二义性
deque<string> Deque3( (istream_iterator<string> (cin)) , istream_iterator<string>() );
通过加括号来提示编译器我们这里提供的是构造函数的参数而非参数声明,因为 (istream_iterator<string> (cin)) 不能解析为变量声明,这个更void f ( (int i)) 不可能是函数声明是一回事。多一对括号不可能解释为合法的声明语句。
2.关于double 和float 区别
一个例子
int main()


{

double x = 1e8;
while(x >0)
x--;


return 0;
}

现在的编译器一秒就可能运行完成,
如果吧doubel x = 1e8 ,换为 float x = 1e8;
C++标准说 :
浮点类型有三种: float ,double, long double,关于精度很显然
如果换成float 答案很诡异,因为取决于float的精度,能否表达0 1e8区间的整数
所以如果换为 float,可能运行一秒,也可能是死循环,因为如果float不能表达0 1e8区间的整数, 因为其中 n-1 = n (由于浮点精度不够)
。
3. 一些拼写代码错误
#include <iostream>
#include <iomanip>

using namespace std;

int main()


{
int x = 1;
for (int i =0 ; i < 100; i++)

{
;
}

// 下面这行代码会干些什么?递增???????/
++x;
std::cout << x << std::endl;
return 0;
}

一个支持标准c++的编译器答案输出是 1
原因很诡异,因为有个有趣的是:注释末尾‘??/’会被转换为'\' ,写个宏的都知道这个就是换行符,所以??/换转换为\ ,而++x就相当于粘贴到注释行的末尾 ,所以++x.,不会起作用,是注释的一部分。
在看一个例子:
一个符号标准 c++的编译器会报多少错误。
struct X


{
static bool f(int *p)

{
return p &&0[p] and not p[1:>>p[2];
}
};
先一步一步的分析
1:0[p] 其实和p[0]一样
2: and not都是有效关键字 ,他们分别是&& 和!
3::>竟然也是合法的,他是]的双字符写法。
所以这个语句会被解析为 return p && p[0] && !p[1]>p[2] ,没有语法错误。
很诡异。