Thread: C++ newbie / linux not so newbie question

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    4

    C++ newbie / linux not so newbie question

    Hey fellas and fella-ettes.

    I am trying to get started with C++ and I have a problem right off the bat. Here is my 1st C++ example:
    Code:
    #include <iostream.h>
    
    
    int main()
    {
        cout << "Hello, World!\n";
           return 0;
    }
    I know this should be very simple, but , I'm getting some errors that I'm not sure what they are or how to fix.

    I started by writing this in Kedit and then I went to a command line where I saved the file as "hello.cpp"
    Then I typed in : g++ hello.cpp

    here is what I got back:

    In file included from /usr/include/c++/3.3.1/backward/iostream.h:31,
    from hello.cpp:1:
    /usr/include/c++/3.3.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
    hello.cpp:8:2: warning: no newline at end of file

    from here, I do not know what to do. did is just try compiling this? and if so, what do I fo next. any help would appreciated

    thanks
    Joe


  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    try replacing

    #include <iostream.h>

    with

    #include<iostream>

    using namespace std;


    the problem is that iostream.h is now deprecated.

  3. #3
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187

    Re: C++ newbie / linux not so newbie question

    or
    Code:
    std::cout << "Hello, World!\n";
    without namepace declaration
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    thanks for the almost immediate reply.

    here is whatI got when I changed the:
    #inculde <iostream.h>

    to:

    #include<iostream>

    hello.cpp: In function `int main()':
    hello.cpp:6: error: `cout' undeclared (first use this function)
    hello.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.)
    hello.cpp:8:2: warning: no newline at end of file

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    Jaguar

    well i think i've got further now but I'm not sure what to do next.

    here is whay I got now after typing in
    : g++ hello.cpp

    hello.cpp:8:2: warning: no newline at end of file

    what is next?

    thanks so much guys

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    you could also do this

    Code:
    include <iostream>
    using namespace std;
    this way u dont have to use std::insertname here every single time.

    as for that try this, goto the last line in your file and add an extra line and your done(that is just hit enter

  7. #7
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    try
    Code:
    using namespace std;
    int main()
    {
        cout<<"hello world!"<<endl;
        return 0;
    }
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  8. #8
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    Code:
    #include <iostream>
    
    
    int main()
    {
      std::cout << "Hello, World!\n";
           return 0;
    }
    worked great.

    thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie question on KDevelop
    By zaphodikus in forum Linux Programming
    Replies: 2
    Last Post: 06-05-2006, 12:57 AM
  2. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  3. newbie linux user question
    By agilman in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2006, 03:50 AM
  4. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  5. Question about LINUX
    By River21 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-17-2001, 06:39 PM