关于c++的问题请教高手
- jinger7281
- 帖子: 23
- 注册时间: 2008-10-05 21:16
关于c++的问题请教高手
最近两天突然对c++感兴趣,但是刚上来就碰了壁,希望c++高手帮小弟解决这个问题,这是我QQ号希望高手能加我详细帮我(验证信息c++
)
这是我的c++程序
#include <iostream.h>
int main(){
cout<<"hello world";
}
这是编译的时候提示
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp:1:22: error: iostream.h: 没有该文件或目录
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
看完之后我感觉头文件不对,就在include里边找这个头文件,终于找到了(在include/c++/4.3有个iostream)并做了如下修改
#include <c++/4.3/iostream>
int main(){
cout<<"hello world";
}
然后出现以下提示
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
这是iostream文件下的内容:
// Standard iostream objects -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2005
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file iostream
* This is a Standard C++ Library header.
*/
//
// ISO C++ 14882: 27.3 Standard iostream objects
//
#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <ostream>
#include <istream>
_GLIBCXX_BEGIN_NAMESPACE(std)
/**
* @name Standard Stream Objects
*
* The <iostream> header declares the eight <em>standard stream
* objects</em>. For other declarations, see
* http://gcc.gnu.org/onlinedocs/libstdc++ ... to.html#10 and the
* @link s27_2_iosfwd I/O forward declarations @endlink
*
* They are required by default to cooperate with the global C library's
* @c FILE streams, and to be available during program startup and
* termination. For more information, see the HOWTO linked to above.
*/
//@{
extern istream cin; ///< Linked to standard input
extern ostream cout; ///< Linked to standard output
extern ostream cerr; ///< Linked to standard error (unbuffered)
extern ostream clog; ///< Linked to standard error (buffered)
#ifdef _GLIBCXX_USE_WCHAR_T
extern wistream wcin; ///< Linked to standard input
extern wostream wcout; ///< Linked to standard output
extern wostream wcerr; ///< Linked to standard error (unbuffered)
extern wostream wclog; ///< Linked to standard error (buffered)
#endif
//@}
// For construction of filebuffers for cout, cin, cerr, clog et. al.
static ios_base::Init __ioinit;
_GLIBCXX_END_NAMESPACE
#endif /* _GLIBCXX_IOSTREAM */
希望高手能加我QQ给我详细解释以下,感激不尽!
)
这是我的c++程序
#include <iostream.h>
int main(){
cout<<"hello world";
}
这是编译的时候提示
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp:1:22: error: iostream.h: 没有该文件或目录
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
看完之后我感觉头文件不对,就在include里边找这个头文件,终于找到了(在include/c++/4.3有个iostream)并做了如下修改
#include <c++/4.3/iostream>
int main(){
cout<<"hello world";
}
然后出现以下提示
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
这是iostream文件下的内容:
// Standard iostream objects -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2005
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file iostream
* This is a Standard C++ Library header.
*/
//
// ISO C++ 14882: 27.3 Standard iostream objects
//
#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <ostream>
#include <istream>
_GLIBCXX_BEGIN_NAMESPACE(std)
/**
* @name Standard Stream Objects
*
* The <iostream> header declares the eight <em>standard stream
* objects</em>. For other declarations, see
* http://gcc.gnu.org/onlinedocs/libstdc++ ... to.html#10 and the
* @link s27_2_iosfwd I/O forward declarations @endlink
*
* They are required by default to cooperate with the global C library's
* @c FILE streams, and to be available during program startup and
* termination. For more information, see the HOWTO linked to above.
*/
//@{
extern istream cin; ///< Linked to standard input
extern ostream cout; ///< Linked to standard output
extern ostream cerr; ///< Linked to standard error (unbuffered)
extern ostream clog; ///< Linked to standard error (buffered)
#ifdef _GLIBCXX_USE_WCHAR_T
extern wistream wcin; ///< Linked to standard input
extern wostream wcout; ///< Linked to standard output
extern wostream wcerr; ///< Linked to standard error (unbuffered)
extern wostream wclog; ///< Linked to standard error (buffered)
#endif
//@}
// For construction of filebuffers for cout, cin, cerr, clog et. al.
static ios_base::Init __ioinit;
_GLIBCXX_END_NAMESPACE
#endif /* _GLIBCXX_IOSTREAM */
希望高手能加我QQ给我详细解释以下,感激不尽!
上次由 jinger7281 在 2016-09-08 17:19,总共编辑 1 次。
- cnkilior
- 论坛版主
- 帖子: 4984
- 注册时间: 2007-08-05 17:40
Re: 关于c++的问题请教高手
#include <iostream.h> ----->>>>#include <iostream>
- jinger7281
- 帖子: 23
- 注册时间: 2008-10-05 21:16
Re: 关于c++的问题请教高手
换成#include <iostream>还是出现这样的提示
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
pinger@pinger-desktop:~$ g++ hello.cpp
hello.cpp: In function ‘int main()’:
hello.cpp:3: 错误: ‘cout’在此作用域中尚未声明
- cnkilior
- 论坛版主
- 帖子: 4984
- 注册时间: 2007-08-05 17:40
Re: 关于c++的问题请教高手
喂给你吃好了
代码: 全选
#include <iostream>
int main(){
using namespace std;
cout<<"hello world";
}
- jinger7281
- 帖子: 23
- 注册时间: 2008-10-05 21:16
Re: 关于c++的问题请教高手
问题解决了
喂给额吃的大哥,有空解释一下这个入门级的东东是怎么回事吗?谢谢了
喂给额吃的大哥,有空解释一下这个入门级的东东是怎么回事吗?谢谢了
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: 关于c++的问题请教高手
iostream.h 应该是可以的, 不知道为什么你的会 file not found
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
- Chine
- 帖子: 204
- 注册时间: 2006-12-22 21:50
- 联系:
Re: 关于c++的问题请教高手
LZ看的是哪个年代的C++?呵呵~
- jinger7281
- 帖子: 23
- 注册时间: 2008-10-05 21:16
Re: 关于c++的问题请教高手
唉!我还以为经典书能学点东西!奶奶的害苦我了!刚才去google了一下,知道是怎么回事了!谢谢各位大哥帮忙
- lerosua
- 论坛版主
- 帖子: 8455
- 注册时间: 2007-11-29 9:41
- 联系:
Re: 关于c++的问题请教高手
还真是喂了啊~~
-
- 帖子: 15
- 注册时间: 2009-02-13 21:49
Re: 关于c++的问题请教高手
......
在#include <iostream.h>的下面一行加一句:
using namespace std;
因为cout是在std这个命名空间里面定义的~你没调用,当然说cout有问题啦~
还有,#include <iostream.h>是C的风格
C++的风格就是用#include <iostream>
其实随便哪种写法效果都一样的
在#include <iostream.h>的下面一行加一句:
using namespace std;
因为cout是在std这个命名空间里面定义的~你没调用,当然说cout有问题啦~
还有,#include <iostream.h>是C的风格
C++的风格就是用#include <iostream>
其实随便哪种写法效果都一样的
- Whistler
- 帖子: 157
- 注册时间: 2006-09-05 11:01
- 联系:
Re: 关于c++的问题请教高手
最新的 gcc 已经像 VS.net 2005 一样,把 iostream.h 之类的取消了。。。
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: 关于c++的问题请教高手
iostream.h 是向后兼容的玩意, 没有命名空间的版本casa 写了:......
在#include <iostream.h>的下面一行加一句:
using namespace std;
因为cout是在std这个命名空间里面定义的~你没调用,当然说cout有问题啦~
还有,#include <iostream.h>是C的风格
C++的风格就是用#include <iostream>
其实随便哪种写法效果都一样的
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。