LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-14-2004, 02:12 AM   #1
webwolf70
Member
 
Registered: Feb 2004
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502

Rep: Reputation: 30
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
 
Old 09-14-2004, 02:13 AM   #2
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 30
#include <iostream>
 
Old 09-14-2004, 02:18 AM   #3
sether
Member
 
Registered: Aug 2004
Posts: 695

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

std::cout << "\nhello world!\n";
 
Old 09-14-2004, 02:21 AM   #4
webwolf70
Member
 
Registered: Feb 2004
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502

Original Poster
Rep: Reputation: 30
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
 
Old 09-14-2004, 02:22 AM   #5
webwolf70
Member
 
Registered: Feb 2004
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502

Original Poster
Rep: Reputation: 30
ok let me give that a try. Thanks.


Webwolf
 
Old 09-14-2004, 02:23 AM   #6
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 30
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.
 
Old 09-14-2004, 02:24 AM   #7
webwolf70
Member
 
Registered: Feb 2004
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502

Original Poster
Rep: Reputation: 30
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

Last edited by webwolf70; 09-14-2004 at 02:26 AM.
 
Old 09-14-2004, 02:27 AM   #8
sether
Member
 
Registered: Aug 2004
Posts: 695

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

g++ first.cc -o first
 
Old 09-14-2004, 02:29 AM   #9
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie needs help with simple program mastervampire Linux - Newbie 1 03-07-2005 06:26 AM
Another ? from a newbie - stuck in a while loop azucarmom Programming 2 12-05-2004 09:41 PM
c++ newbie - help debug simple program please mymojo Programming 4 11-27-2003 05:17 AM
Just a Newbie stuck ramzi Linux - Newbie 7 08-21-2003 02:41 PM
Newbie Stuck in Slackware8! NightSky Linux - Newbie 5 12-18-2001 11:40 PM


All times are GMT -5. The time now is 11:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration