c++中的流提取操作符
Stream extraction operator in C++
我有以下代码:
#include<iostream>
using namespace std;
int main()
{
int x=3;
cout<<x++<<++x<<x++<<++x<<endl;
return 0;
}
输出应为3557但它是6747。为什么? ?
也:
#include<iostream>
using namespace std;
int main()
{
int x=3;
cout <<x++<<endl;
cout<<++x<< endl;
cout<<x++<< endl;
cout<<++x<< endl;
return 0;
}
以上代码给出:3.557(每一个数字换行)有人能解释一下原因吗?
int x=3;
cout<<x++<<++x<<x++<<++x<<endl;
这是未定义的行为,因此您可以轻松地获得任何结果。
int x=3;
cout <<x++<<endl; // x = 3, post incremented to 4...
cout<<++x<< endl; // here x = 4 and preincremented to x = 5
cout<<x++<< endl; // x = 5 , postincremented to 6...
cout<<++x<< endl; // so here x = 6 but preincremented to 7
未定义的行为和序列点
cout和printf
相关文章:
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么istream不支持右值提取
- 如何设置一个范围来提取我想要获得的信息
- 视觉工作室项目.提取源文件夹名称
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 从字符串中提取整数并形成一个数组
- C ++中的StringStream有助于使用向量从字符串中提取逗号分隔的整数,而不是空格分隔的整数,为什么?
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- 从 std::vector<无符号字符>切片中提取 int?
- Istream提取操作符:如何检测解析失败
- 重载自定义类集的提取操作符
- 使用文件提取操作符读取int或string
- 使用PoDoFo-lib从PDF操作符中的数组TJ中提取文本
- c++中重载流提取操作符
- 流插入/提取操作符重载函数的原型属于哪里?
- 类函数的c++提取操作符
- 如何在类中实现提取操作符
- c++流提取操作符重载
- c++中的流提取操作符