ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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
Distribution: NetBSD x86; Slackware Linsux i686 (A billion kilometers away)
Posts: 101
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.