LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ Newbie stuck on first simple program (https://www.linuxquestions.org/questions/programming-9/c-newbie-stuck-on-first-simple-program-230368/)

webwolf70 09-14-2004 01:12 AM

C++ Newbie stuck on first simple program
 
I am doing the C++ tutorial at http://www.cplusplus.com/doc/tutorial/tut1-1.html

I am also extremly new to this and I am learning as I go.

I used kwrite and copied it down exactly.

// my first program in C++

#include <iostream.h>

int main ()
{
cout << "Hello World!";
return 0;
}


Then I made another with some minor modifications. But with each one I get this message,

"[root@localhost first]# g++ first.cc -o first
In file included from /usr/include/c++/3.3.2/backward/iostream.h:31,
from first.cc:7:
/usr/include/c++/3.3.2/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.
"

Also When I compile this, how do I execute it? I tried just typing in "first" but nothing happened.


What am I doing wrong?


Thanks


Webwolf

sether 09-14-2004 01:13 AM

#include <iostream>

sether 09-14-2004 01:18 AM

oh wait, and you've gotta put "std::" before cout

std::cout << "\nhello world!\n";

webwolf70 09-14-2004 01:21 AM

Quote:

Originally posted by sether
#include <iostream>

I took out the .h and kept #include <iostream>


"
// my first program in C++

#include <iostream>

int main ()
{
cout << "Hello World!";
return 0;
}
"

This is the error meassge I got now.


"[root@localhost first]# g++ first.cc -o first
first.cc: In function `int main()':
first.cc:12: error: `cout' undeclared (first use this function)
first.cc:12: error: (Each undeclared identifier is reported only once for each function it appears in.)"


Webwolf

webwolf70 09-14-2004 01:22 AM

ok let me give that a try. Thanks.


Webwolf

sether 09-14-2004 01:23 AM

yeah, the second post i made. you've gotta put std::

is the tutorial teaching you not to do this?

to run "first",

./first

after you've compiled it with no errors.

webwolf70 09-14-2004 01:24 AM

Thank you. It worked without any error messages. Now how do I execute it? lol.

Edit: Never mind, lol. I just read your post. We must be typing at the same time. And no. The original post showed what they told me to type. You can see it if you click on the link above. It is right there on that page, or the next one.


Webwolf

sether 09-14-2004 01:27 AM

./first (that's a period, a slash, and the name of the program) given that you did

g++ first.cc -o first

sether 09-14-2004 01:29 AM

yeah so they changed the standard. you don't need to put ".h" at the end of header files anymore. and a few other things. you can either
a) read man g++ and see what option you need to use to tell the compiler you're using old skool style c++ or
b) use a different tutorial.

is that the tutorial i suggested in another thread? sorry about that if it is.


All times are GMT -5. The time now is 10:36 AM.