C++ 类型';std::string';和';常量字符[2]';不兼容
我正在使用以下编译器:C++ 类型';std::string';和';常量字符[2]';不兼容,c++,xcode,c++17,clion,C++,Xcode,C++17,Clion,我正在使用以下编译器: Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我正在运行此版本的MacOS:
10.15.4
我正在使用此版本的CLion
:
CLion 2020.1.1
Build #CL-201.7223.86, built on April 29, 2020
Runtime version: 11.0.6+8-b765.40 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.4
GC: ParNew, ConcurrentMarkSweep
Memory: 1987M
Cores: 6
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins: com.intellij.clion-swift, org.toml.lang, org.rust.lang
以下是CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.15)
project(clion_error)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-Wall -Wextra -pedantic -Werror -pedantic-errors -Wshadow -Wstrict-aliasing)
add_executable("clion_error" main.cpp)
这里是main.cpp
:
#include <string>
int main(int, char**)
{
std::string my_string = "hello";
return 0;
}
#包括
int main(int,char**)
{
std::string my_string=“hello”;
返回0;
}
以下是如何重现错误:
code
检查代码…
OK
类型“std::string”和“const char[6]”不兼容
为什么会报告此错误?这确实是CLion 2020.1的一个错误。只有通过
code | Inspect code
运行代码分析或禁用clangd服务器时,才会出现此问题 请提供您是否有#包括?这是一个实际的编译器错误,还是一些只在IDE中出现的错误?无法重现:@ThomasSablik我已经澄清了这个问题。请提供一个。