Question

I'm working on [Bjarne_Stroustrup]Programming-Principles-and-Practice-Using-C++ book from 2008, 5. chapter called Errors is using std_lib_facilities.h and function called error.

Here is example :

if(x<=0) error("non-positive x");
if(y<=0) error("non-positive y");
int area1=area(x,y);

Since I use Visual Studio 2012 which don't have std_lib_facilities.h, this error handler is not working! What is iostream's error handling function and where can I find and study it?

Was it helpful?

Solution

The C++ Standard Library's header files (iostream, vector, etc.) don't have .h on the end. (Most third-party libraries, however, do use the .h.) Since std_lib_facilities.h does have a .h, it's reasonable to assume it's not a standard library and not something that Visual C++ should be expected to provide.

In this case, a quick Google search reveals that it's provided with your book and downloadable from http://www.stroustrup.com/Programming/std_lib_facilities.h.

OTHER TIPS

std_lib_facilities.h is a helper header written by Bjarne Stroustrup.

It provides the most common standard headers (in the global namespace) and minimal exception/error support.

You can find it here under shortcut: Standard library access header.

An error function is defined as follows:

// error() simply disguises throws:
inline void error(const string& s)
{
    throw runtime_error(s);
}

Visual Studio

Here you can find a tutorial on how to get std_lib_facilities.h working on VS.


There is also note for a students...

Students: please don't try to understand the details of headers just yet. All will be explained. This header is primarily used so that you don't have to understand every concept all at once.

Since im using Visual Studio 2012 which dont have "std_lib_facilities.h", this error handler is not working! What is iostream's error handling function and where can i find and study it?

std_lib_facilities.h header is not something which c++ standard has provided. Hence you are getting such error in VS2012. You need to write your own logic and put it into the some file and include it into your program.

You may implement your own basic version of error() function as follows:

#include<iostream>
template<typename T>
void error(const T& msg) {
 std::cerr<<msg<<std::endl;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top