LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-10-2003, 05:20 AM   #1
ashesh
Member
 
Registered: Feb 2003
Location: Kharagpur
Distribution: RH8, RH9, FC2
Posts: 112

Rep: Reputation: 15
Arrow Does my c++ compiler have a bug???


I have got Linux RH8.0...

I have written the following code:

#include <iostream>

int main()
{
int x;
cout << "Hello World" << endl;
cin>>x;
cout<<" X = "<<x<<"\n";
}

It gives error on my systemsaying the C++/3.2/iostream file has some problem etc...
This program worked well on a system with RH7.1

Someone suggested to have
"using namespace std" after the include statement and the program works well.

I am still confused why I have done this and whether there is some real problem with my compiler?

I dont know how I can know what my compiler is?
 
Old 06-10-2003, 08:05 AM   #2
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 60
I can answer the last question

# What compiler version do I have
gcc --version
 
Old 06-10-2003, 12:36 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
If you use
#include <iostream.h>
It should be OK (but not 100% sure).
 
Old 06-10-2003, 01:26 PM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Leave it as:

Code:
#include <iostream>
using namespace std;
There is nothing wrong with your compiler. This is the way it's supposed to be done nowadays Check out the following threads; this question has been asked many times here:

http://www.linuxquestions.org/questi...threadid=48417
http://www.linuxquestions.org/questi...threadid=43963
 
Old 06-10-2003, 02:01 PM   #5
jrpretz
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Rep: Reputation: 0
You can
#include <iostream.h>
and avoid the
using namespace std;

but the compiler complains that iostream.h is deprecated.
 
Old 06-10-2003, 11:01 PM   #6
ashesh
Member
 
Registered: Feb 2003
Location: Kharagpur
Distribution: RH8, RH9, FC2
Posts: 112

Original Poster
Rep: Reputation: 15
[ashesh@ecl5 ashesh]$ gcc --version
gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Yes, the error was because i was not including the
using namepsace std;

and it seems all the new compilers will need the above statement.

Moreover, #include<iostearm.h> doesn't work; it has to be <iostream> and then the "using namespace std;"
 
Old 06-11-2003, 04:24 AM   #7
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Re: Does my c++ compiler have a bug???

Quote:
Originally posted by ashesh
I have got Linux RH8.0...

I have written the following code:

#include <iostream>

int main()
{
int x;
cout << "Hello World" << endl;
cin>>x;
cout<<" X = "<<x<<"\n";
}

It gives error on my systemsaying the C++/3.2/iostream file has some problem etc...
This program worked well on a system with RH7.1

Someone suggested to have
"using namespace std" after the include statement and the program works well.

I am still confused why I have done this and whether there is some real problem with my compiler?

I dont know how I can know what my compiler is?
Code:
#include<iostream>

int main() {
  int x;
  std::cout << "Hello World" << std::endl;
  std::cin >> x;
  std::cout << " X = " << x << std::endl;
  return 0;
}
The standard library classes are contained in a namespace called std.

Code:
#incude<iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
  int x;
  cout << "Hello World" << endl;
  cin >> x;
  cout << "X = " << x << endl;
  return 0;
}
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
Free86 bug or nVidia bug?? ProtoformX Linux - Software 2 05-12-2004 02:38 AM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 04:31 AM
No compiler to compiler the compliler NewtonIX Linux - Newbie 13 11-03-2003 05:32 AM
compile a compiler without a compiler? lackluster Linux - General 18 01-02-2003 07:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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