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.
then i opened the terminal and went to TC. there i gave the following command.
Code:
$ g++ hello1.C -o hello
but i got the following messages
Code:
hello1.C:1:21: error: iostream.h: No such file or directory
hello1.C: In function ‘int main()’:
hello1.C:4: error: ‘cout’ was not declared in this scope
hello1.C:4: error: ‘\n’ was not declared in this scope
what does all this mean?? and why is this error here???
You need to use "iostream" rather than "iostream.h". I believe this is part of the newer C++ standard (ANSI C++?), but I'm not sure. Some distros provide the older headers (i.e. the ones with the ".h") for backwards compatibility, but it seems that Ubuntu isn't one of them. Also, you'll need a "using namespace std;" under your include directives and before main(), i.e.
Code:
#include <iostream>
using namespace std;
int main()
{
// Code here
}
This is because cout is declared in the "std" namespace, so you need to specify that you want to use that namespace.
I am trying to run a simple program in ubuntu. GCC is installed. But still the following errors are being flashed .
I hope you use Synaptic for package management. It is easier than other front ends to apt. In Synaptic find the packages named libstdc++6-?.?-dev with various numbers for the ?.?. You should have one of those installed. If you do already, I've mis diagnosed the problem. If you don't, you need to install one. I'm not certain which one. Assuming you already have libstdc++6 installed, look at the version number of that and select the matching version of libstdc++6-?.?-dev
For example, on my Mepis system I have version 4.3.2-1.1 of libstdc++6 installed and the same version of libstdc++6-4.3-dev installed. There is libstdc++6-4.1-dev and libstdc++6-4.2-dev available, not installed. But of course neither of them has a version number starting with 4.3
Quote:
Originally Posted by Nylex
You need to use "iostream" rather than "iostream.h". I believe this is part of the newer C++ standard (ANSI C++?), but I'm not sure. Some distros provide the older headers (i.e. the ones with the ".h") for backwards compatibility, but it seems that Ubuntu isn't one of them.
I think all of that is incorrect.
iostream.h is part of the package libstdc++-dev in Ubuntu. I doubt any distribution would split up the std C++ headers the way you describe. I think the backwards compatibility ones are always included.
Since the OP can't find iostream.h, I assume he is missing all those headers (current ones as well as backwards compatibility ones).
I think there is some higher level package group that would include libstdc++-dev as well as other packages the OP will need. But I don't know how to look up which groups include a package. Installing the required packages one at a time as you hit error messages will get the job done. Installing the group would be easier if you knew its name.
Quote:
Also, you'll need a "using namespace std;" under your include directives and before main(), i.e.
Code:
#include <iostream>
using namespace std;
int main()
{
// Code here
}
This is because cout is declared in the "std" namespace, so you need to specify that you want to use that namespace.
That is another difference between iostream.h and iostream. If you use iostream.h, you don't need the using namespace std line.
I'm not particularly recommending using iostream.h instead of iostream. I just don't think that is the OP's current problem.
You need to use "iostream" rather than "iostream.h". I believe this is part of the newer C++ standard (ANSI C++?), but I'm not sure. Some distros provide the older headers (i.e. the ones with the ".h") for backwards compatibility, but it seems that Ubuntu isn't one of them. Also, you'll need a "using namespace std;" under your include directives and before main(), i.e.
Code:
#include <iostream>
using namespace std;
int main()
{
// Code here
}
This is because cout is declared in the "std" namespace, so you need to specify that you want to use that namespace.
Ya u r absolutely correct..... that is where the problemwas.... i am habitual of using the older version of Turbo C++ IDE in windows where i use the <iostream.h> and i never used the
using namespace std stuff..... so i was getting the errors.....
thanks a lot.... now the programs are back to the running mode....
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094
Rep:
Quote:
Originally Posted by shubham chakraborty
Ya u r absolutely correct..... that is where the problemwas.... i am habitual of using the older version of Turbo C++ IDE in windows where i use the <iostream.h> and i never used the
using namespace std stuff..... so i was getting the errors.....
thanks a lot.... now the programs are back to the running mode....
You could always do this:
Code:
#ifdef __TURBOC__
#include <iostream.h>
#define EXIT_SUCCESS 0
#else
#include <iostream> //Who ever thought of dropping the file extension :|
using namespace std;
#endif
int main(){
cout<<"Hello world!" <<endl;
return EXIT_SUCCESS;
}
Portability is good!
Last edited by smeezekitty; 11-28-2009 at 12:18 PM.
#ifdef __TURBOC__
#include <iostream.h>
#define EXIT_SUCCESS 0
#else
#include <iostream> //Who ever thought of dropping the file extension :|
using namespace std;
#endif
int main(){
cout<<"Hello world!" <<endl;
return EXIT_SUCCESS;
}
Portability is good!
Yeah, but any compiler should accept <iostream> and "using namespace std;", so you might as well just use that and not confuse yourself when you look back on your code.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094
Rep:
Quote:
Originally Posted by JohnGraham
Yeah, but any compiler should accept <iostream> and "using namespace std;", so you might as well just use that and not confuse yourself when you look back on your code.
even turbo C++?
Code:
Compiling HELLOCPP.CPP:
•Error HELLOCPP.CPP 1: Unable to open include file 'IOSTREAM'
Error HELLOCPP.CPP 2: Declaration syntax error
Error HELLOCPP.CPP 4: Undefined symbol 'cout'
Error HELLOCPP.CPP 4: Undefined symbol 'endl'
Compiling HELLOCPP.CPP:
•Error HELLOCPP.CPP 1: Unable to open include file 'IOSTREAM'
Error HELLOCPP.CPP 2: Declaration syntax error
Error HELLOCPP.CPP 4: Undefined symbol 'cout'
Error HELLOCPP.CPP 4: Undefined symbol 'endl'
Well... obviously not, at least not with the version you're using
I stand corrected, then. The headers without the .h extension are indeed the "newer" headers, not to be confused with the old ones. There may be something to be said about a compiler that doesn't support them, but if you want to use that compiler, that's your choice.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.