Visual c + + - 自动更正

时间:2013-01-10 19:43:35

标签: c++ visual-studio

#include <iostream>

int main()
{
    cout << "Can't find cout, did you mean std::cout?";
    return 0;
}

如果这是java代码eclipse / intellij会告诉我它找不到cout,它会给我一个可能解决这个错误的列表,例如std::cout

我从来没有在c ++中看到类似的内容,但我却错过了这个功能。它对于在java中导入库非常有用,因为你只需键入类似cout的内容,IDE就会建议你#include <iostream>而不跳到文件的顶部。

visual c ++中是否存在类似的东西? (或其他IDE)

1 个答案:

答案 0 :(得分:2)

我不了解IDE,但clang会这样做:

$ clang++ test.C 
test.C:5:5: error: use of undeclared identifier 'cout'; did you mean 'std::cout'?
    cout << "Can't find cout, did you mean std::cout?";
    ^~~~
    std::cout
/usr/include/c++/4.2.1/iostream:63:18: note: 'std::cout' declared here
  extern ostream cout;          ///< Linked to standard output
                 ^
1 error generated.

最近的GCC版本也会这样做:

$ g++ test.C 
test.C: In function ‘int main()’:
test.C:5:5: error: ‘cout’ was not declared in this scope
test.C:5:5: note: suggested alternative:
In file included from test.C:1:0:
/usr/include/c++/4.7.1/iostream:62:18: note:   ‘std::cout’