Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Compiling C++ programs on Red Hat 8.0
Results 1 to 9 of 9

Thread: Compiling C++ programs on Red Hat 8.0

  1. #1
    sampathks
    Guest

    Compiling C++ programs on Red Hat 8.0

    Hi Folks

    My machine : Intel 2.0 GHz Celeron; 256 mb ram; 40 GB hdd

    I have 3 partitions; 1) 15GB XP; (2) 10GB Win 2003 server
    (3) Red Hat 8.0 (with all the packages, installed as a standalone server);

    When I compile a c++ program I get an error. Following is my code
    Code:
    #include <iostream>
    int main()
    {
       cout << "welcome to c++" << endl;
       return 0;
    }
    The program is named first.cc
    I compile with c++ first.cc OR g++ first.cc
    I am getting the following errors

    In the program:
    "cout" is undeclared;
    "cout" first use in the function main();

    I checked with rpm query regarding the presence of gcc package for c++; it is there..

    Can somebody help me please.....??????????



  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    304

    Re:Compiling C++ programs on Red Hat 8.0

    Try this:

    #include <iostream>

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

    int main.........

    The using directive is required with the new c++ headers. Many people say "using namespace std;" rather than doing a "using" statement for each class needed, but this is basically the same thing as using the old header style <iostream.h> and is discouraged.

  3. #3

    Re:Compiling C++ programs on Red Hat 8.0

    I think either add under the #include

    using namespace std;

    or either make the #include

    #include <iostream.h>
    AMD Athlon 2200+ 1.8Ghz
    1280MB PC-3200 CAS2.5 RAM
    ATI Radeon 9600 Pro 128MB AGP
    Western Digital WDC WD2500JB-00FUA0 250GB 7200 rpm ATA/133
    Seagate ST3200822A 200GB 7200 rpm ATA/133
    Western Digital WDC WD1200BB-00CAA1 120GB 7200 rpm ATA/133
    Western Digital WDC WD800BB-00CAA1 80GB 7200 rpm ATA/133
    Maxtor OneTouch 2HA43R32 1TB 7200 rpm USB 2.0
    D-Link DFE-530TX+ 10/100 NIC
    D-Link DWL-G520 Rev.A
    Debian 5.0r1 Lenny

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    304

    Re:Compiling C++ programs on Red Hat 8.0

    Both forms you mentioned are discouraged.

    <iostream.h> is the old way of doing it. The newest standard requires <iostream>

    using namespace std;
    should only be used if you are truly using every item in the std namespace. People use it for convenience, but the standard discourages it. You SHOULD do a using statement for each piece you need to use such as:
    using std::cin;
    rather than using the entire namespace. Why? Because it is possible that the next standard will not allow inclusion of a global namespace. The standard was changed to this format to get away from global namespace inclusion. I suspect (but could be wrong) that the only reason they left the ability to include a global namespace was to make the transition to the new style easier for the more experienced C++ programmers. It can be done with a "using namespace std;" but if the standard changes later, you'll have to relearn how to include items. Doing a using on each item needed will teach you good habits now for a standard that is likely to happen later.

    It should be noted that this is just my opinion and although it is influenced by statements my instructors have made, it's still an opinion. Many examples still use "using namespace std;" but I don't think those examples are very clean code.

  5. #5

    Re:Compiling C++ programs on Red Hat 8.0

    OK thats hard to understand for me, can you retype his code as it SHOULD be ?
    Ta
    Its better to regret something you have done than to regret something you havent done :P

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    304

    Re:Compiling C++ programs on Red Hat 8.0

    What he had:
    Code:
    #include <iostream>
    int main()
    {
       cout << "welcome to c++" << endl;
       return 0;
    }
    What it should be:
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    int main()
    {
       cout << "welcome to c++" << endl;
       return 0;
    }

  7. #7

    Re:Compiling C++ programs on Red Hat 8.0

    Cool - thanks for that. Starting to dabble a bit in C++ myself, and im about as advanced as that bit of code lol so its good to know how i should be going about things
    Its better to regret something you have done than to regret something you havent done :P

  8. #8

    Re:Compiling C++ programs on Red Hat 8.0

    gaxprels, That's actually really kewl. I didn't know that you could declare specific parts you wanted to use like that. I'll probably still end up using the namespace until they take it away from me.
    AMD Athlon 2200+ 1.8Ghz
    1280MB PC-3200 CAS2.5 RAM
    ATI Radeon 9600 Pro 128MB AGP
    Western Digital WDC WD2500JB-00FUA0 250GB 7200 rpm ATA/133
    Seagate ST3200822A 200GB 7200 rpm ATA/133
    Western Digital WDC WD1200BB-00CAA1 120GB 7200 rpm ATA/133
    Western Digital WDC WD800BB-00CAA1 80GB 7200 rpm ATA/133
    Maxtor OneTouch 2HA43R32 1TB 7200 rpm USB 2.0
    D-Link DFE-530TX+ 10/100 NIC
    D-Link DWL-G520 Rev.A
    Debian 5.0r1 Lenny

  9. #9
    Senior Member
    Join Date
    Nov 2001
    Posts
    304

    Re:Compiling C++ programs on Red Hat 8.0

    HEHE...
    If you really want to make your code painful to look at, rather than do a using namespace std; or individual using statements for each object, you can do this:

    Code:
    #include <iostream>
    
    int main ( void ) {
       std::cout << "Welcome to code hell" << std::endl;
       return 0;
    }
    This is fine for cases where you are only using a cout or endl once or twice in your code, but when you use them a lot, it's better to do the:
    using std::cout; and using std::endl; at the top instead

    It's all a matter of scope resolution. The "::" is called the scope resolution operator, for those who are just learning and didn't already know. Take care and keep coding!

Similar Threads

  1. Any GPL FTP programs ?
    By Compunuts in forum Windows - General Topics
    Replies: 9
    Last Post: 12-05-2009, 04:08 PM
  2. Compiling BASIC programs on Linux
    By tech291083 in forum Redhat / Fedora
    Replies: 2
    Last Post: 10-20-2007, 09:13 AM
  3. compiling c programs in suse linux
    By sajeerfazil in forum Suse
    Replies: 3
    Last Post: 04-28-2007, 01:56 PM
  4. What programs do you use?
    By Compunuts in forum Windows - General Topics
    Replies: 31
    Last Post: 09-14-2006, 09:21 AM
  5. win 98 programs
    By lisinda in forum Windows - General Topics
    Replies: 0
    Last Post: 05-31-2005, 02:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •