的iostream [英] Iostream

查看:85
本文介绍了的iostream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



似乎当我尝试编译这个简单的代码时,我收到一条错误消息我想b $ b相信是来自g ++找不到IOSTREAM头文件。我在/usr/include/c++/3.2.2/中找到了

头文件,这就是为什么它包含

之类的。建议?


我正在跑红帽9


代码:


#include < / usr / include / c ++ / 3.2.2 / iostream>


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''未声明(首先使用此函数)


project2.C:6 :(每个未声明的标识符只报告一次


函数出现

-

通过 http://dbforums.com 发布

推荐答案

" ncstate"< me ********* @ dbforums.com>写在留言中

新闻:35 **************** @ dbforums.com ...
"ncstate" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...

当我尝试编译这个简单的代码时,我得到了一个错误消息我相信是来自g ++没有找到IOSTREAM头文件。我在/usr/include/c++/3.2.2/中找到了
头文件,所以这就是为什么它包含了
那样。建议?

我正在运行红帽9

代码:

#include< / usr / include / c ++ / 3.2.2 / iostream>

int main()

{

cout<< endl<< endl<< "杰夫" << endl;

cout<< E115 Sec 010 B << endl;

cout<< Hello World << endl<< endl<< endl;

返回0;

}

错误:

project2.C:在函数`int main( )'':

project2.C:6:`cout''未声明(首先使用此功能)

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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I''m running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>

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)

project2.C:6: (Each undeclared identifier is reported only once for each

function it appears




''cout''对象在''std''命名空间中声明。你应该

用std ::作为前缀,或者声明你使用的是

名称:


使用std :: cout;

使用std :: endl; //以及


获得一本体面的C ++书。

Victor



The ''cout'' object is declared in the ''std'' namespace. You should
either prefix it with "std::" or declare that you''re using that
name:

using std::cout;
using std::endl; // as well

Get a decent book on C++.

Victor


" ncstate"< me ********* @ dbforums.com>写在留言中

新闻:35 **************** @ dbforums.com ...
"ncstate" <me*********@dbforums.com> wrote in message
news: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 of
an 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 9
This 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 installed
and/or configured incorrectly.

Note that from the language''s perspective <iostream> is a
standard *header* name, it does *not* signify a "file" name.
Many if not most implementations do provide an actual file
with the same or a similar name to implement a standard header,
but this is an implementation detail, not specified or
required by the language. E.g. a compiler could provide the
required declarations as ''hard coded'' if it wanted and would
still be conforming -- the #include statement would still be
required 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 identifiers
except 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 restricted
by 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 this
diagnostic a bit confusing too the first time I saw it.

/david

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."


这篇关于的iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆