我已经成功解决了,主要是参考stackoverflow和github上的
https://stackoverflow.com/questions/66346896/how-to-fix-ycm-printing-use-of-undeclared-identifier-cout-or-no-member-namedhttps://github.com/ycm-core/YouCompleteMe/issues/2885#issuecomment-360835891解决方法就是:你的 .ycm_extra_conf.py 文件里面需要配置c++版本的路径/usr/include/c++/7.2.1 要放在 /usr/include 前面!这个很重要!
可以通过 g++ --version命令查看你的g++版本,c++的include目录是在/usr/include/c++下面,根据你的版本自己找。
You are getting these errors because the order of your -isystem flags is wrong: /usr/include/c++/7.2.1 must be included before /usr/include. Try the following .ycm_extra_conf.py file:
def FlagsForFile( filename ):
return { 'flags': [
'-Wall',
'-Wextra',
'-Werror',
'-std=c++11',
'-x',
'c++',
'-isystem',
'/usr/include/c++/7.2.1',
'-isystem',
'/usr/include/c++/7.2.1/x86_64-pc-linux-gnu',
'-isystem',
'/usr/include/c++/7.2.1/backward',
'-isystem',
'/usr/local/include',
'-isystem', '/usr/include',
] }