为什么 CLion 不允许我使用嵌套的三元运算符?
Why does CLion not allow me to have nested ternary operators?
我正在尝试在 C++14 中使用嵌套的三元表达式。我的代码如下:
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 5;
string result = i % 2 == 0 ? "a" : i % 3 == 0 ? "b" : "c";
return 0;
}
我正在使用 CLion。我在最后一个 nexted 表达式 i % 3 == 0 ? "b" : "c"
说 Type 'const char[2]' and 'const char[2]' are not compatible
时出错。我做错了什么?
如果有帮助,这是我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(TestCLion)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES relop.cpp)
add_executable(TestCLion ${SOURCE_FILES})
这是一个known bug in CLion。
代码将编译无误。 (使用 CLion 2017.3.1,GCC 6.3.0)
我正在尝试在 C++14 中使用嵌套的三元表达式。我的代码如下:
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 5;
string result = i % 2 == 0 ? "a" : i % 3 == 0 ? "b" : "c";
return 0;
}
我正在使用 CLion。我在最后一个 nexted 表达式 i % 3 == 0 ? "b" : "c"
说 Type 'const char[2]' and 'const char[2]' are not compatible
时出错。我做错了什么?
如果有帮助,这是我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(TestCLion)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES relop.cpp)
add_executable(TestCLion ${SOURCE_FILES})
这是一个known bug in CLion。
代码将编译无误。 (使用 CLion 2017.3.1,GCC 6.3.0)