LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ERROR: iostream.h: No such file or directory...‘cin’ was not declared in this scope (https://www.linuxquestions.org/questions/linux-newbie-8/error-iostream-h-no-such-file-or-directory-%91cin%92-was-not-declared-in-this-scope-812990/)

FelipeGamma 06-08-2010 07:00 PM

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,


paulsm4 06-08-2010 07:09 PM

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

FelipeGamma 06-08-2010 08:02 PM

Thanks paulsm4...


All times are GMT -5. The time now is 08:38 PM.