Menu

Equivilent C++ code in Dev C++?

2003-02-08
2012-09-26
  • Nobody/Anonymous

    Hi, I have a few questions. I am taking a Visual C++ class, and our instructor recommended that we download Dev C++ so that would could do the work out of our book at home. Well I tried doing a sample program that was in our book in Dev C++, and all I get is errors when I compile it. This exact same code comiles/executes correctly in Visual C++, but it doesn't work in Dev C++. I was wondering if someone could help me with figuring out the equivalent code. Here is the sample project:

    //calculates and displays required number of single rolls of wallpaper

    #include <iostream.h>
    using namespace std;

    int main()
    {

        //declare variables
        float length = 0.0;
        float width = 0.0;
        float height = 0.0;
        float rollCoverage = 0.0;
        float perimeter = 0.0;
        float area = 0.0;
        float rolls = 0.0;
       
        //enter input items
        cout << "Enter room length: ";
        cin >> length;
        cout << "Enter room width: ";
        cin >> width;
        cout << "enter ceiling height: ";
        cin >> height;
        cout << "Enter single roll coverage: ";
        cin >> rollCoverage;
       
        //calculate perimeter, area and number of single rolls
        perimeter = (length + width) * 2;
        area = perimeter * height;
        rolls = area / rollCoverage;
       
        //display output item
        cout << "Single rolls: " << rolls << endl;
       
        return 0;
        }
        //end of main function

    The errors I get are as follows:

    *22 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp:3
    iostream.h: No such file or directory.

    * C:\Documents and Settings\Owner\Desktop\Untitled1.cpp
    [Warning] In function `int:

    *19 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp
    `cout' undeclared

    *19 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp
    (Each undeclared

    *20 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp
    `cin' undeclared

    *34 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp
    `endl' undeclared

    So what do i need to do in order to get this Visual C++ code to work in Dev C++?

     
    • Nobody/Anonymous

      The C++ used is the standard C++. DevC++ is an IDE and not another version of C++,  as VC++ is in microsoft. The VC++ is known for not being "standard", a lot of Gates only stuff in it.

      You may need to understand  standard C++ better, a direct fix from VC++ to standard could and would be a time long task every project i would think.

       
    • Nobody/Anonymous

      In this case,
      (1) iostream.h is depricated you need to use just iostream
      (2) You need to look into making some additions to your C++ include path, as iostream is in a lower level directory.  One suggestion is to have the following there:
      C:\<dev path>\include
      C:\<dev path>\include\cpp
      C:\<dev path>\include\c++
      C:\<dev path>\include\c++\backward
      C:\<dev path>\include\c++\bits
      C:\<dev path>\include\c++\mingw32\bits
      C:\<dev path>\include\c++\ext
      C:\<dev path>\include\c++\mingw32

      Final note.  It is almost never helpful to say "this code works under compiler xyz", there are diffferences in compilers, thats reality.

      Wayne

       
    • Nobody/Anonymous

      By the way, your code is correct, Dev is just not correctly configured. Go to "Tools > Compiler Options > Directories > C++ Includes" and add the following paths
      (where dev-path is where you installed dev-cpp)

      ------------------------------------------------------------
      C:\<dev path>\include
      C:\<dev path>\include\cpp
      C:\<dev path>\include\c++
      C:\<dev path>\include\c++\backward
      C:\<dev path>\include\c++\bits
      C:\<dev path>\include\c++\mingw32\bits
      C:\<dev path>\include\c++\ext
      C:\<dev path>\include\c++\mingw32
      -------------------------------------------------------------
      --nilson

       
    • Nobody/Anonymous

      Actually, strictly speaking, the code is *NOT* correct nilson, as it includes iostream.h, not iostream, so it not compliant with the C++ standard.

      Our fixes for the path agree though, because, well..., I stole it from one of your posts.

      :-)

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.