C++ 致命错误:字符串:没有这样的文件或目录

C++ 致命错误:字符串:没有这样的文件或目录,c++,cmake,g++,C++,Cmake,G++,在使用cmake编译时,我收到以下消息: In file included from scanner.lex:6: C:\Users\uriya\CLionProjects\untitled1\output.hpp:4:10: fatal error: string: No such file or directory 4 | #include <string> | ^~~~~~~~ compilation terminated. make.ex

在使用cmake编译时,我收到以下消息:

In file included from scanner.lex:6:
C:\Users\uriya\CLionProjects\untitled1\output.hpp:4:10: fatal error: string: No such file or directory
    4 | #include <string>
      |          ^~~~~~~~
compilation terminated.
make.exe[3]: *** [CMakeFiles\untitled1.dir\build.make:88: CMakeFiles/untitled1.dir/lex.yy.c.obj] Error 1
make.exe[3]: *** Waiting for unfinished jobs....
make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/untitled1.dir/all] Error 2
make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/untitled1.dir/rule] Error 2
make.exe: *** [Makefile:117: untitled1] Error 2
奇怪的是,我使用
g++-std=c++11-o hw2 parser.tab.cpp output.cpp lex.yy.c

CGube和这个命令有什么区别?< /P>是扫描器。LX被编译成C或C++。也许我不知道,但是我认为所有的东西都是自动编译成C++的。我如何选择编译成什么?“我如何选择编译成什么?”-通过使用源文件的适当扩展名来选择编译器
.c
是c源代码的扩展。如果文件<代码> LX.YY.C./COD>包含C++代码,那么它的扩展是错误的。它只包含C代码,但这实际上对我起作用!谢谢你的帮助@Uriyasama顺便说一句:您可以覆盖源文件的语言,无论其扩展名为何;您只需要设置正确的源文件属性:
set_source_files_properties(lex.yy.c properties LANGUAGE CXX)
#ifndef _236360_2_
#define _236360_2_

#include <string>
using namespace std;

namespace output {
    extern const string rules[];
    void printProductionRule(int ruleno);
    void errorLex(int lineno);
    void errorSyn(int lineno);
};

#endif
cmake_minimum_required(VERSION 3.13)
project(untitled1)

set(CMAKE_CXX_STANDARD 11)

add_executable(untitled1 parser.tab.cpp output.cpp lex.yy.c)