LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-22-2004, 04:03 PM   #1
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Rep: Reputation: 30
trying c++


hello folks im trying to learn c++ never done anything like it befor so i got a book called"c++ a beginers guide . any way iv got to the stage where it says lets run a simple programme so iv copied every thing in the book letter for letter as follows
/*
This is a simple C++ programme.
call this file sample.cpp
*/
include <iostream>
using namespace std;

// A C++ programme begins at main().
int main()
{
cout << "C++ is power programming.";

return 0;
}
i wrote all this in to a text editor i then opend a terminal and typed "g++ sample.cpp"
i get this error message
[root@x1-6-00-10-dc-a7-f1-8f root]# g++ sample.cpp
sample.cpp:5: `iostream' was not declared in this scope
sample.cpp:6: syntax error before `using'
sample.cpp: In function `int main()':
sample.cpp:11: `cout' undeclared (first use this function)
sample.cpp:11: (Each undeclared identifier is reported only once for each
function it appears in.)
[root@x1-6-00-10-dc-a7-f1-8f root]#
now i dont think i should really be doing this as root but i tried it as regular user and it did not work so i thought i would just give it a go any way ill appreciate any help offerd.
thanks for any replys
 
Old 08-22-2004, 04:14 PM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Just a guess, but swap include <iostream> and using namespace std;?
 
Old 08-22-2004, 04:17 PM   #3
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
Code:
#include <iostream>
You forgot the #, silly person.
 
Old 08-23-2004, 09:29 AM   #4
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
letter for letter who am i kidding cheers
 
Old 08-23-2004, 09:49 AM   #5
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
hello again iv corrected it so it looks like this
/*
This is a simple C++ programme.
call this file sample.cpp
*/
#include <iostream>
using namespace std;

// A C++ programme begins at main().
int main()
{
cout << "C++ is power programming.";

return 0;
}
but when i open a terminal and type "g++ sample.cpp"
my computer looks like it is trying to do something then it just does nothing
any more help please the book dont even tell me what is going to happen so i dont know what to expect when i do type the command "g++ sample.cpp
thanks nige
 
Old 08-23-2004, 10:01 AM   #6
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
g++ like most unix commands displays nothing if all went well. so after you run the command you should have a binary called a.out, this is exectable corresponding to your code - you need to run it like

./a.out

you can change the name of the output file with the -o option ie

g++ -o sample sample.cpp

will produce an executable named sample which you could then run like above

./sample
 
Old 08-23-2004, 10:08 AM   #7
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
cheers buddy much appreciated
 
Old 08-23-2004, 11:55 AM   #8
Gnute
Member
 
Registered: Apr 2003
Location: Kuwait
Distribution: NetBSD x86; Slackware Linsux i686 (A billion kilometers away)
Posts: 101

Rep: Reputation: 15
Re: trying c++

Quote:
Originally posted by master
...so i got a book called"c++ a beginers guide...
Great choice, I got the exact same book.
 
Old 08-23-2004, 01:32 PM   #9
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
i only got my book a couple of days a go when i opend it i thought what have i done but now im starting to enjoy it
 
Old 08-23-2004, 01:35 PM   #10
Gnute
Member
 
Registered: Apr 2003
Location: Kuwait
Distribution: NetBSD x86; Slackware Linsux i686 (A billion kilometers away)
Posts: 101

Rep: Reputation: 15
I know, it introduces the concepts a bit too fast in module 1, but starts going slowly afterwards.
I'm not really the kind fo spend hours reading text, but I just skip through the examples to learn.
 
  


Reply



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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 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
Open Source Consulting | Domain Registration