LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2011, 02:30 AM   #1
soumyaranjan4ever
LQ Newbie
 
Registered: Aug 2011
Location: Bhubaneswar, Orissa
Distribution: Ubuntu
Posts: 3

Rep: Reputation: Disabled
Question C++ compilation problem in Ubuntu


After i create a file with text editor, when i use the compile command

gcc filename.cpp

fatal error - iostream.h: No such file or directory
compilation terminated.

And when i try
gcc -o filename.cpp
it says
gcc: no input files.

Please Help me.

Last edited by soumyaranjan4ever; 08-21-2011 at 02:34 AM.
 
Old 08-21-2011, 02:41 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
For C++ programs, you use g++, rather than gcc (so that the standard C++ library is linked automatically). Also, you should be using "iostream", rather than "iostream.h". The latter is the older form of the header and it probably doesn't exist on your system (it certainly doesn't on mine).

Also, the -o flag is used to specify the name of the executable, so you're not actually giving a source file to be compiled, hence the error message in the second case.
 
Old 08-21-2011, 02:47 AM   #3
soumyaranjan4ever
LQ Newbie
 
Registered: Aug 2011
Location: Bhubaneswar, Orissa
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: Disabled
Sir, my example file is ---

gedit name.cpp

#include<iostream>
int main()
{
cout<<"I hope this works";
}

When i am compiling with command
g++ name.cpp it gives 2 messages-- 1. In function 'int main()'
2. error - 'cout' not declared in this scope.
 
Old 08-21-2011, 02:48 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Ah yes. You also need the line "using namespace std;" after the #include, because cout, endl and friends are in the namespace called "std" (which you'll learn about later if you get that far!).

Edit: Also, in future, please post code between [code] tags to preserve indentation.
 
Old 08-21-2011, 02:57 AM   #5
soumyaranjan4ever
LQ Newbie
 
Registered: Aug 2011
Location: Bhubaneswar, Orissa
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank U sir, after over a year of C programming, i was into C++ classes for over a week. i had covered much but inability to compile and test some programs was irritating. But thank U again sir, i have compiled my first C++ program. I will always be grateful to U.

Regards,
Soumya Ranjan (India)
 
Old 08-21-2011, 02:58 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Please mark your thread as solved by using the "Thread Tools" at the top. Also, please write words out in full here.
 
  


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
syslog-ng compilation for mipsel using ubuntu manishkumar6288@gmail.co Programming 5 12-03-2010 01:53 PM
Ubuntu 10.4 freeze during compilation MOFH Linux - Newbie 1 07-10-2010 07:42 PM
Compilation problems installing omnet++ on Ubuntu 8.10 ronino Linux - Software 3 04-10-2009 04:52 AM
Using ubuntu and fedora, compilation difference go939 Linux - Software 1 12-04-2007 06:21 AM
make compilation problem-ubuntu mihalisla Linux - General 3 08-28-2006 01:15 PM


All times are GMT -5. The time now is 12:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration