?
Solved

Cannot open include file: 'math': No such file or directory

Posted on 2005-03-25
6
Medium Priority
?
738 Views
Last Modified: 2013-11-18
Why cant it open it?


/***********************************************************
*                                                          *
* Program name: ex6.1.cpp                                  *
* Author: Stuart Downes                                    *
* 17th March    2005                                        *
*                                                          *
* //Purpose:                                               *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* How to run program: Run ex6.1.cpp                        *
*                                                          *
*                                                          *
*                                                          *
* Documentation:                                           *
*                                                          *
*                                                          *
*                                                          *
* References:                                              *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* File Formats:                                            *
*                                                          *
*                                                          *
* Limits or restrictions:                                  *
*                                                          *
*                                                          *  
*                                                          *
* Revisions                                                *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* Error Handling                                           *
*                                                          *
*                                                          *
*                                                          *
* Special Comments                                         *
*                                                          *
***********************************************************/

// Write a program to find the square of the distance between two points.

// Find the distance only if you want to do the independent research needed
// to perform a square root in C++.

#include <math>
#include <iostream>


float x1;       // x1
float y1;       // y1
float x2;       // x2
float y2;       // y2

float distance;     // distance
// float square;       // square of the distance

main ()
{

    // Read Co-ordinates
      std::cout << "Enter x1 ";
      std::cin >> x1 >> "/n";

      std::cout << "Enter y1 ";
      std::cin >> y1 >> "/n";

      std::cout << "Enter x2 ";
      std::cin >> x2 >> "/n";

      std::cout << "Enter y2 ";
      std::cin >> y2 >> "/n";

      
      // Calculate Distance

    distance = Sqrt(sqr(x2-x1) + sqr(y2-y1);

      std::cout << distance;
 

return (0);

}
0
Comment
Question by:stuartdownes
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13633244
Hi stuartdownes,

Try math.h
#include <math.h>

David Maisonave :-)
Cheers!
0
 
LVL 30

Expert Comment

by:Axter
ID: 13633260
The math header is a C header files.
In C++ all the C header files will either have an .h extension, or a c prefix.

#include<cmath>  //Good, and in the namespace std

#include<math.h>  //In the global namespace

0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 13636874
Which compiler do you use stuartdownes? If you use an ancient C++ compiler like a Turbo C++, you'll have to #include<math.h> as Axter pointed out. Instead if you're using the mordern compilers like VC++, they some in STL (Standard Library and Header files) so #include<math> is fine. If neither work, either someone deleted math.h (TC++) or your compiler is screwed (VC++).

Reagrds,

Ram
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 30

Accepted Solution

by:
Axter earned 800 total points
ID: 13636919
>>Instead if you're using the mordern compilers like VC++, they some in STL (Standard Library and Header files)
>>so #include<math> is fine.

No it's not.  <math> is not part of the C++ standard.  And <math> is NOT part of STL.
<math.h> is a C library, and all C libraries in the C++ standard have either a *.h extension, or a C prefix.

There is not <math> header in the C++ standard.

See table 12 in section (17.4.1.2 Headers) paragraph 3 in official C++ standards:
**********************************************************************
The facilities of the Standard C Library are provided in 18 additional headers, as shown in Table 12:
Table 12—C++ Headers for C Library Facilities
<cassert> <ciso646> <csetjmp> <cstdio> <ctime>
<cctype> <climits> <csignal> <cstdlib> <cwchar>
<cerrno> <clocale> <cstdarg> <cstring> <cwctype>
<cfloat> <cmath> <cstddef>
**********************************************************************

Paragraph 4 continues with the following:

**********************************************************************
Except as noted in clauses 18 through 27, the contents of each header cname shall be the same as that of the
corresponding header name.h, as specified in ISO/IEC 9899:1990 Programming Languages C (Clause 7),
or ISO/IEC:1990 Programming Languages—C AMENDMENT 1: C Integrity, (Clause 7), as appropriate,
as if by inclusion. In the C++ Standard Library, however, the declarations and definitions (except for
names which are defined as macros in C) are within namespace scope (3.3.5) of the namespace std.
**********************************************************************


So there is NO <math> header in the C++ standard.
Any compiler that supports <math> header is supporting a non-standard header.
Your code should avoid using such non-standard header and instead use the standard C++ header <cmath> or <math.h>

This does not apply to the STL headers, in which you should use the extensionless version <iostream> <vector>
0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 13636932
Wow Axter! I didn't know <math> wasn't STL! I use an <math.h> to date and it gives me no problems whatsoever. However, the modern compilers complain for <iostream.h> and you have to change it to <iostream>.

Thanks for correcting me. I really appreciate it.

Regards,

Ram
0
 
LVL 30

Expert Comment

by:Axter
ID: 13636958
>>However, the modern compilers complain for <iostream.h> and you have to change it to <iostream>.

As I stated in the last part of my previuos comment, it does not apply to STL headers like <iostream>.

In fact, it's the opposite.
There is NO *.h version for the STL headers in the C++ standard.  So <iostream.h> is not part of the C++ standard.

The only *.h headers in the C++ standards are the C-Standard headers.
If the header is a C++ header, then it doesn't have a *.h version in the C++ standard.

So just as you shouldn't use <math> non-standard header, you also should not use a <iostream.h> non-standard header.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question