C++ - 垂直线操作员.它有什么作用
C++ - Vertical Line Operator. What does it do?
当你将标志传递给函数时,使用运算符'|'做什么,它的正确名称是什么?我将如何在自己的函数中实现这一点?感谢您的帮助。
它是
按位或的。例如:
(1 | 2) == 3
(5 | 3) == 7
嗯,这取决于。垂直线运算符|
绘制一条垂直线,就像水平线运算符 '-' 绘制一条水平线一样。还有弟兄们||
和=
分别画两条平行的竖线或横线:
#include <algorithm>
#include <iostream>
#include <iterator>
struct graphic
{
void operator-(int n) {
*std::fill_n(std::ostream_iterator<char>(std::cout), n, '-')++ = 'n';
}
void operator=(int n) {
*std::fill_n(std::ostream_iterator<char>(std::cout), n, '=')++ = 'n';
}
void operator|(int n) {
std::fill_n(std::ostream_iterator<char>(std::cout, "n"), n, '|');
}
void operator||(int n) {
std::fill_n(std::ostream_iterator<char const*>(std::cout, "n"), n, "||");
}
};
int main()
{
graphic g;
g - 10;
g = 10;
g | 4;
g || 4;
}
相关文章:
- archive_read_support_filter_all() 有什么作用?
- 当我们为(;;) 写作时,它做了什么?for 循环中的双分号有什么作用?
- 这个递归函数有什么作用?运行时的复杂性是多少?
- DrawShadow 中的 Elevation 究竟有什么作用?
- 测试"stream >> char"有什么作用?
- "uFlags &= ~CHN_PANNING"命令有什么作用?
- GCC 的 -Wpsabi 选项究竟有什么作用?压制它意味着什么?
- int** a = new int*[n]();这个函数有什么作用?
- C++ 此函数调用之前的(void)有什么作用?
- i+=(i&-i) 有什么作用?它是便携式的吗?
- 这个size_t在 lambda 中有什么作用?C++代码
- 数组下标运算符 ([ ]) 对数组有什么作用?
- 结构之外的节点 * head 有什么作用?
- 重载括号运算符有什么作用?
- clang的"-Ofast"选项在实践中有什么作用,特别是对于与gcc的任何差异?
- std::make_unique_for_overwrite() 对 std::make_unique() 有什么作用?
- 运算符 delete[] 有什么作用?
- 下面的代码有什么作用?c++
- 这个陈述'p = I.ptr<uchar>(i);有什么作用?
- 这个嵌套的名称空间定义有什么作用