Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> C++ Compilation, g++ error
beni
post Apr 20 2004, 01:13 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 22
Joined: 18-March 03
Member No.: 562



I've RHL 9 (kernel 2.4.20) and the standard gcc/g++ that ships with the distro. I included the iostream header as <iostream.h>, and got an error msg from g++ about some deprecation. Then I changed the header file to <iostream>. Then the compiler fasils to ercognise the cout function. Now can please anyone tell me how to compile a C++ program using g++?
Go to the top of the page
 
+Quote Post
michaelk
post Apr 20 2004, 03:44 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,800
Joined: 23-January 03
Member No.: 360



should be:
#include <iostream>
using namespace std;

If I remember it was just a warning not an error if you used iostream.h instead of iostream.
Go to the top of the page
 
+Quote Post
Hemant
post Apr 21 2004, 07:23 AM
Post #3


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



Yeah...exactly..new ISO c++ standards suggest following way of including header files..
#include <iostream>

thus the old style is deprecated..you can use it..but it means that support will be removed from future versions of g++.
now the second line...
using namespace std;
is required because...keywords like..cout,endl,cin are not in the current namespace...thus compiler will not recognise these keywords..unless you specify which namespace to use.
thus you can have two styles of coding...
CODE
#include <iostream>
using namespace std;
int main()
{
       cout<<"Hello World"<<endl;
       return 0;
}


or the other style could be like..this..
CODE
#include <iostream>
int main()
{
    std::cout<<"Hello World"<<std::endl;
    return 0;
}


or another style code could be..
CODE
#include <iostream>
using namespace std::cout;
using namespace std::cin;
using namespace std::endl;
int main()
{
   cout<<"Hello World"<<endl;
   return 0;
}


The idea behind this style is...you don't use the entire namespace..but only these three keywords..will belong to std
namespace.


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
beni
post Apr 22 2004, 02:41 AM
Post #4


Whats this Lie-nix Thing?
*

Group: Members
Posts: 22
Joined: 18-March 03
Member No.: 562



Thnx guys. The help is really appreciated smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 15th December 2017 - 08:41 PM