LinuxQuestions.org
Visit Jeremy's Blog.
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 03-19-2002, 01:46 PM   #1
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES / FC/ OES / CentOS
Posts: 614

Rep: Reputation: 32
Unhappy c++ code how to compile and iostream.h


hello!
I`am just starting to programm unter linux.
I have some experice in programming with c++.
My question is:

include <iostream.h>

is this working?
are the header files always the same ?
1. is iostream.h iomanip.h eg. known to the compiler under linux?

2. can i write a programm with the vi and than compile this file with a console command? And if... how would this look?


thanx
 
Old 03-19-2002, 02:16 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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

Code:
#include <iostream.h>

int main()
{
std::cout << "arse" << std::endl;
return 0;
}
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.
 
Old 03-19-2002, 06:38 PM   #3
Zellius
LQ Newbie
 
Registered: Jan 2002
Location: UK
Distribution: RedHat 7.2
Posts: 14

Rep: Reputation: 0
#include <iostream.h>

int main()
{
std::cout << "arse" << std::endl;
cout << "Hole!";
return 0;
}
 
Old 09-03-2002, 05:33 AM   #4
mace
Member
 
Registered: Apr 2002
Distribution: redhat7, 7.1, 7.2, 8.0, mandrake, debian2.2, 3, suse
Posts: 176

Rep: Reputation: 30
g++ blah.cpp -o blah
./blah
 
Old 09-03-2002, 06:25 AM   #5
aditya
Member
 
Registered: Aug 2002
Distribution: RH 7.x
Posts: 71

Rep: Reputation: 15
that's easy

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 "./")

And the output is:
#Hello
#

Hope you get it.
bye.

And the output
 
Old 09-03-2002, 08:30 AM   #6
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
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
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't compile c++ code with g++ malb Programming 5 07-25-2005 06:54 PM
how i compile a source code? nazib Linux - General 5 02-27-2005 09:13 AM
"#include <iostream.h>" does not compile ambuj Linux - Software 7 01-28-2004 08:56 AM
why cant i compile my c++ code in Mdk9.1 m_dma Mandriva 9 01-09-2004 08:36 PM
How to compile source code... Grim Reaper Linux - Newbie 3 04-26-2002 11:28 AM

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

All times are GMT -5. The time now is 03:55 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