VictorThe ''cout'' object is declared in the ''std'' namespace. You shouldeither prefix it with "std::" or declare that you''re using thatname:using std::cout;using std::endl; // as wellGet a decent book on C++.Victor" ncstate"< me ********* @ dbforums.com>写在留言中 新闻:35 **************** @ dbforums.com ..."ncstate" <me*********@dbforums.com> wrote in messagenews:35****************@dbforums.com... 看来当我尝试编译这个简单的代码我收到一条错误消息我相信是来自g ++没有找到IO STREAM头文件。 不,它告诉你它无法找到 的声明你使用过的标识符(''cout' ')。 i在/usr/include/c++/3.2.2/中找到了头文件,这就是为什么它包含在那样的原因。建议? 不要包括它''那样''。 我正在运行红帽9 这没关系。 C ++是一种独立于平台的语言。 代码: #include< / usr / include / c ++ / 3.2.2 / iostream> 更改为: #include< iostream> 如果这不起作用,然后你的编译器安装了 和/或配置错误。 请注意,从语言的角度来看< iostream>是一个 标准*标题*名称,它*不*表示文件名称。 许多(如果不是大多数)实现提供实际文件 ,使用相同或相似的名称来实现标准标题, 但是这是一个实现细节,未指定或该语言需要。例如。编译器可以提供 所需的声明为硬编码,如果它想要并且 仍然符合要求 - #include语句仍然是但是需要)。 [从下面的代码中删除了无偿的空格] int main() { cout<< endl<< endl<< "杰夫" << endl; cout<< E115 Sec 010 B << endl; cout<< Hello World << endl<< endl<<返回0; 错误: project2.C:在函数`int main()''中: project2.C:6:`cout''未声明(首次使用此功能) 这是因为''cout''(以及所有标准库)标识符 除了宏在名称空间''std''中声明。) project2.C:6 :(每个未声明的标识符只报告一次 出现的功能 it seems when i try to compile this simple code I get an error message i believe is from g++ not finding the IOSTREAM header file.No, it''s telling you it cannot find the declaration ofan identifier you''ve used (''cout'').i found the header file in /usr/include/c++/3.2.2/ so that is why it is included like that. suggestions?Don''t include it ''like that''. I''m running red hat 9This doesn''t matter. C++ is a platform independent language. code : #include </usr/include/c++/3.2.2/iostream>Change to:#include <iostream>If this does not work, then your compiler is installedand/or configured incorrectly.Note that from the language''s perspective <iostream> is astandard *header* name, it does *not* signify a "file" name.Many if not most implementations do provide an actual filewith the same or a similar name to implement a standard header,but this is an implementation detail, not specified orrequired by the language. E.g. a compiler could provide therequired declarations as ''hard coded'' if it wanted and wouldstill be conforming -- the #include statement would still berequired however).[Gratuitous whitespace removed from code below] int main() { cout << endl << endl << "Jeff" << endl; cout << "E115 Sec 010 B" << endl; cout << "Hello World" << endl << endl << endl; return 0; } errors: project2.C: In function `int main()'': project2.C:6: `cout'' undeclared (first use this function)This is because ''cout'' (and all standard library identifiersexcept macros are declared in namespace ''std''). project2.C:6: (Each undeclared identifier is reported only once for each function it appears #include< iostream> int main() { std :: cout<<" Hello world \ n" ;; 返回0; } 或 #include< iostream> 使用std :: cout; int main() { cout<<" Hello world \ n"; 返回0; } 或 #include< iostream> 使用命名空间std; int mai n() { cout<< Hello world \ n; 返回0; } (如果需要,''范围'' cout''可以进一步限制 将''using''指令或声明放在 ''main()''函数中。) 注意:虽然大多数实现在没有它的情况下都可以工作,但是'/ b> b''endl''的声明由< ostream>提供。 允许(但不是必须)由 < iostream>提供。 ''endl''也在命名空间''std''中。 (它的''全名''是''std :: endl'') BTW,你正在阅读哪些C ++书? -Mike#include <iostream>int main(){std::cout << "Hello world\n";return 0;}or#include <iostream>using std::cout;int main(){cout << "Hello world\n";return 0;}or#include <iostream>using namespace std;int main(){cout << "Hello world\n";return 0;}(If desired, the scope of ''cout'' can be further restrictedby putting the ''using'' directive or declaration inside the''main()'' function.)Note: while most implementations will work without it,the declaration for ''endl'' is provided by <ostream>.It is allowed to be, but not required to be, provided by<iostream>. ''endl'' is also in namespace ''std''. (Its''full name'' is ''std::endl'')BTW, which C++ book(s) are you reading?-Mike ncstate写道: [snip - 重新排列]ncstate wrote:[snip - rearranged] #include< / usr / include / c ++ / 3.2.2 / iostream> 你可以#include< iostream> int main() { cout<< endl<< endl<< "杰夫" << ENDL; [snip] project2.C:在函数`int main()'': project2.C:6:`cout''未声明(首先使用此函数) project2.C: 6 :(每个未声明的标识符仅针对它出现的每个函数报告一次 #include </usr/include/c++/3.2.2/iostream>You can just #include <iostream> int main() { cout << endl << endl << "Jeff" << endl;[snip] project2.C: In function `int main()'': project2.C:6: `cout'' undeclared (first use this function) project2.C:6: (Each undeclared identifier is reported only once for each function it appears 尝试std :: cout和std :: endl或''使用命名空间std;''我第一次看到它时发现这个 诊断有点令人困惑。 / david - 作为一名科学家,Throckmorton知道,如果他曾经在回声室中吹风,他将永远不会听到它的结束。Try std::cout and std::endl or ''using namespace std;'' I found thisdiagnostic a bit confusing too the first time I saw it./david--"As a scientist, Throckmorton knew that if he were ever to break wind inthe echo chamber, he would never hear the end of it." 这篇关于的iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 15:32