以下是我编写的代码片段:
int n,i,j;
map<int,int>mp;
vector<int>vec;
cin>>n;
for(i=0; i<n; i++)
{
cin>>j;
mp[j]==0? mp[j]=1,vec.push_back(j): mp[j]=1;
}
Run Code Online (Sandbox Code Playgroud)
对于for循环内的第二行,CodeBlocks-16.01 版本显示以下错误:
second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
Run Code Online (Sandbox Code Playgroud)
但是当我将行更改为:
second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
Run Code Online (Sandbox Code Playgroud)
没有错误。以下行有什么问题?
mp[j]==0? vec.push_back(j), mp[j]=1: mp[j]=1;
Run Code Online (Sandbox Code Playgroud)