红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > Ubuntu

关于c++的问题请教高手

发布时间:2009-02-13 10:13:25来源:红联作者:jinger7281
最近两天突然对c++感兴趣,但是刚上来就碰了壁,希望c++高手帮小弟解决这个问题,这是我QQ号希望高手能加我详细帮我(728079912验证信息c++

这是我的c++程序
#include
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
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
#include
#include

_GLIBCXX_BEGIN_NAMESPACE(std)

/**
* @name Standard Stream Objects
*
* The header declares the eight standard stream
* objects
. 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给我详细解释以下,感激不尽!
文章评论

共有 2 条评论

  1. kirayamato868 于 2009-02-14 12:09:47发表:

    呃……没看太懂……但我觉得应该是:
    #include
    using namespace std;
    int main()
    {
    cout<<"Hello world!"<return(0);
    }

  2. wangdu2002 于 2009-02-13 19:21:34发表:

    我不是高手,但我知道你学习的方法不对,学习C++编程首先是要买书,建议到书店去多转下,两本书是最起码的要求,第一本是C++Primer中文版每四版,第二本是GNU编程指南。至少第一本是绝不可少的,第二本能买新版的中文译本估计很难,只能用电子书来对付了。然后照书实践,每天至少看书和实践三小时以上,三个月后,估计可以入门了。以后再找本C++GUI之类的Qt4.4以上版本的书来学习真正的开发初阶吧!