【问题标题】:Why YouCompleteMe still show syntax warning when I include the correct C++ library?为什么当我包含正确的 C++ 库时 YouCompleteMe 仍然显示语法警告?
【发布时间】:2016-09-18 09:16:11
【问题描述】:

当我包含所需的库时,“#include..”行不会显示任何警告。但是当我使用该库中的函数时,我发现 Vim 显示“..使用未声明的函数......”。似乎没有正确包含该库。所以我想知道如何解决这个问题?

附上本题截图:

【问题讨论】:

    标签: c++ vim youcompleteme


    【解决方案1】:

    尝试按如下方式包含它:

    #include <stdlib.h>  //use <> instead of  "" 
    

    此外,“printf”函数来自“cstdio”库,因此请尝试实现该库,

    #include <stdio.h>
    

    更新

    解决该问题的最简单方法是;

    包含 stdio.h 库

    #include <stdio.h>
    

    然后,而不是打字;

    printf('s');
    

    你会的,

    printf("s");
    

    现在,如果你真的想打印一个字符's',那么使用,

    printf("%c", 's');   // Tells the printf function that 's' is a character
    

    最终代码如下所示;

    #include <stdio.h>      
    int main(int argc, char** argv) {
        printf("s"); 
        printf("%c", 's');
        return 0;
    }
    

    现在,您的评论是“cout”不起作用。为了让“cout”工作,您需要包含 iostream 库:

    #include <iostream>
    

    然后,您可以在代码中使用“cout”;

    std::cout << 's';
    std::cout << "s";
    

    或者你可以包含“namespace std”和“iostream”库以避免在“cout”之前使用std::

    include <iostream>
    using namespace std;
    

    此后,使用不带 std:: 的 cout

    cout << 's';
    cout << "s";
    

    最终的代码是;

    #include <iostream>
    using namespace std;
    
    int main(int argc, char** argv) {    
        cout << 's';
        cout << "s";
        return 0;
    }
    

    如果您想了解有关 iostream 库中的内容以及如何使用它的更多信息,我建议您使用此站点:

    http://www.cplusplus.com/reference/iostream/

    另外,对于 stdio.h,

    http://www.cplusplus.com/reference/cstdio/

    【讨论】:

    • 还是不行。实际上,当我包含 iostream 并使用命名空间 std 时,“...cout...”行也不起作用。所以我认为这不是这个原因造成的。
    • 我编辑(更新)答案,逐步解决您的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 2022-01-05
    • 2011-08-14
    • 1970-01-01
    • 2022-01-16
    • 2022-11-27
    相关资源
    最近更新 更多