<?=运算符C ++大于问号等于符号 [英] <?= operator C++ greater less question mark equals sign
问题描述
我看到在代码中使用了<?=和>?=: http://community.topcoder.com/stat? c = problem_solution& rm = 151152& rd = 5854& pm = 2923& cr = 310333
I saw <?= and >?= used in a code: http://community.topcoder.com/stat?c=problem_solution&rm=151152&rd=5854&pm=2923&cr=310333
我试图在没有包含文件的情况下进行编译,以测试它是否是标准文件,但没有用.然后,我添加了包含,但仍然会出现相同的错误:
I tried to compile without the includes to test if it's standard, but it didn't work. I then added the includes, but it still gives the same error:
question-mark.cpp:15:5:错误:?"之前的预期主表达式 令牌问题mark.cpp:15:6:错误:预期的主要表达式 在"="令牌问号.cpp:15:9之前:错误:预期在:"之前 ‘;’令牌问题-mark.cpp:15:9:错误:预期的主要表达式 在;"令牌之前
question-mark.cpp:15:5: error: expected primary-expression before ‘?’ token question-mark.cpp:15:6: error: expected primary-expression before ‘=’ token question-mark.cpp:15:9: error: expected ‘:’ before ‘;’ token question-mark.cpp:15:9: error: expected primary-expression before ‘;’ token
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int x = 3;
int y = 2;
x >?= y;
printf("x = %d\n", x);
return 0;
}
以下是链接中的代码中使用它的方式:
Here's how it is used in the code from the link:
x <?= h[i][j]; // x = (h[i][j] < x) ? h[i][j] : x;
我该如何进行这项工作?
How can I make this work?
推荐答案
这些是GCC扩展程序运算符. a <?= b
的含义与a = min(a, b)
相同(>?=
是"max"运算符),但是它只计算一次左侧表达式.当a
是变量时,这并不重要,但是当a
表示表达式时,尤其是在表达式具有副作用时,这可能会有所不同.例如,在
These are GCC extensions operators. a <?= b
has the same meaning as a = min(a, b)
(>?=
is the "max" operator), but it evaluates its left-hand side expression only once. This is not important when a
is a variable, but it may make a difference when a
represents an expression, especially when the expression has a side effect. For example, in
*dest++ <?= *src++;
dest++
中的++
仅被评估一次.
两个运算符现在都已已弃用.
这篇关于<?=运算符C ++大于问号等于符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!