1
#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)

4

1 回答 1

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’
于 2013-01-10T19:45:52.247 回答