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.
looks ok as far as includes go, well it should be #include of course. it just searches on the defined include path. i've not got g++ configured on my system properly, but the header files are normally included from /usr/include/g++/ and so forth
that will work. I wrote it in pico, and compiled it with just "g++ test.cpp" and it print the obvious to the screen. header files do change, but not a noticable amount esp on something as engrained as the glibc and such like. Are you aware of the benefits of the whole cout stuff as opposed to the C style printf("arse"); commands? Also are you aware of what #include #define and such like actaully mean. They are preprocessor instructions, and are reomved before the program is compiled, and are replaced with said header files and such like.
If you have vi editor:
type # vi <filename.cpp>
If you have vim editor:
type # vim <filename.cpp>
Remember the "cpp" extension, else compiler will give error.
Then, write the program in Insert mode (I hope you know vi):
#include <iostream> /*In linux , ".h" isn't necessary with some headers */
int main() //void main gives error in linux.
{
cout<<"Hello"<<endl; //No great need to give namespace
return 0;
}
Save this file.
type at prompt:
# gcc <filename.cpp>
The gcc complier will save the exe file with name a.out. The Linux compliers directly produce executables unless explicitely specified.
Change the file permission to include 'executable permission' if it does not have one.Then type:
# ./a.out
(Don't forget the "./")
int main() //void main gives error in linux.
( Posted by Aditya )
As far as the return type is concerned, I think the gnu compiler will take care of it. But it is good to keep this in mind.
--Sarin
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.