LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 06-08-2010, 07:00 PM   #1
FelipeGamma
LQ Newbie
 
Registered: Jun 2010
Location: Colombia
Distribution: Ubuntu
Posts: 2

Rep: Reputation: 0
ERROR: iostream.h: No such file or directory...‘cin’ was not declared in this scope



I create a simple code for add two number:
Code:
#include<iostream.h>
#include<stdio.h>

main()
{
int num1, num2, sum;
cout<< "input the first number: ";
cin>> num1;
cout<< "input the second number: ";
cin>> num2;
sum= num1+num2;
cout<< "The result is: ";
cout<< sum;
}
But when I compile the code:
Code:
$ c++ sum.c
The console shows the next error:
Quote:
suma.c:1:21: error: iostream.h: No such file or directory
suma.c:3:18: error: stlib.h: No such file or directory
suma.c: In function ‘int main()’:
suma.c:8: error: ‘cout’ was not declared in this scope
suma.c:9: error: ‘cin’ was not declared in this scope
I search the answer to my problem in various forums but I can't solve the problem.
I think that is due to I need some package or that I don't install the necessary libraries.

Thanks,

 
Old 06-08-2010, 07:09 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

"iostream.h" is an anachronism.

Modern C++ programs should use "#include <iostream>" instead.

Here's an example:
Code:
#include <iostream>
 
using namespace std;
 
int 
main(int argc, char* argv[])
{
  cout << "Hello world" << endl;
  return 0;
}
'Hope that helps .. PSM

PS:
Of course, maybe you just didn't install the complete development package.

For Redhat or Centos, for example, you'd run something like:
Quote:
yum install gcc gcc-c++ make autoconf automake gawk binutils
for Ubuntu, an equivalent command might be:
Quote:
sudo aptitude install build-essential

Last edited by paulsm4; 06-08-2010 at 07:13 PM.
 
Old 06-08-2010, 08:02 PM   #3
FelipeGamma
LQ Newbie
 
Registered: Jun 2010
Location: Colombia
Distribution: Ubuntu
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks paulsm4...
 
  


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
Problem compiling (error: ‘strcmp’ was not declared in this scope) beboppinbobby Linux - Newbie 4 12-19-2009 01:33 AM
aria2, ‘assert’ was not declared in this scope , compiler error adityasharma Linux - Newbie 4 07-31-2009 05:51 AM
Compiling tesseract-2.03: error: ‘INT32’ was not declared in this scope J_Szucs Linux - Software 10 03-05-2009 02:35 PM
/ArgParser.cpp:207: error: 'atoi' was not declared in this scope Jane2008 Linux - Newbie 2 11-07-2008 09:23 AM
Error Prompt - 'Execute_command was not declared in this scope. Please help! thhuang Linux - Newbie 1 11-05-2007 12:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 PM.

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