#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)
我不了解 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’