Installing" std_lib_facilities.h" on MinGW

This is a discussion on Installing" std_lib_facilities.h" on MinGW within the C++ Programming forums, part of the General Programming Boards category; Hi, A. I'm a total beginner.I want to use MinGW, which I already downloaded. I looked at the help but ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    NYC
    Posts
    2

    Installing" std_lib_facilities.h" on MinGW

    Hi,
    A. I'm a total beginner.I want to use MinGW, which I already downloaded. I looked at the help but I would like to really know exact steps how to do it. My basic question is under item "C" -- items "A" and "B" provided background.

    B. The instructions from PPP("Programming Principles and Practice Using C++") Stroustrup book says:
    "Note that different compilation systems and programmer communities
    have different conventions for where to put header files. The book
    assumes that a header file is in the same directory/folder as the .cpp
    files and uses "plain" #include "std_lib_facilities.h". If that
    doesn't work, try #include "../std_lib_facilities.h" (one level up)
    and #include "../../std_lib_facilities.h" (two levels up)".


    C. I was trying to figure this out on my own, and here what I thought was the way to do it. Is it correct?

    1. Either find a folder that stores .cpp files or if I can't find
    it,create one. I would put it in the C:\MinGW folder
    2. I will copy the the following, (and save it as
    "std_lib_facilities.h" in the folder mentioned above):


    Code:
    /* 
             simple "Programming: Principles and Practice using C++" course header 
     to 
             be used for the first few weeks. 
             It provides the most common standard headers (in the global 
     namespace) 
             and minimal exception/error support. 
     
            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. 
     
            Revised April 25, 2010: simple_error() added 
     */ 
     
    #ifndef H112 
     #define H112 201004L 
     
    #include<iostream> 
     #include<fstream> 
     #include<sstream> 
     #include<cmath> 
     #include<cstdlib> 
     #include<string> 
     #include<list> 
     #include<vector> 
     #include<algorithm> 
     #include<stdexcept> 
     
    //------------------------------------------------------------------------------ 
     
    #ifdef _MSC_VER 
     #include <hash_map> 
     using stdext::hash_map; 
     #else 
     #include <ext/hash_map> 
     using __gnu_cxx::hash_map; 
     
    namespace __gnu_cxx { 
     
        template<> struct hash<std::string> 
         { 
             size_t operator()(const std::string& s) const 
             { 
                 return hash<char*>()(s.c_str()); 
             } 
         }; 
     
    } // of namespace __gnu_cxx 
     
    
    #endif 
     //------------------------------------------------------------------------------ 
     
    #define unordered_map hash_map 
     
    //------------------------------------------------------------------------------ 
     
    typedef long Unicode; 
     
    //------------------------------------------------------------------------------ 
     
    using namespace std; 
     
    template<class T> string to_string(const T& t) 
     { 
             ostringstream os; 
             os << t; 
             return os.str(); 
     
    } 
     
    
    struct Range_error : out_of_range {     // enhanced vector range error 
     reporting 
             int index; 
             Range_error(int i) :out_of_range("Range error: "+to_string(i)), 
     index(i) { } 
     }; 
     
    
    // trivially range-checked vector (no iterator checking): 
     template< class T> struct Vector : public std::vector<T> { 
             typedef typename std::vector<T>::size_type size_type; 
             Vector() { } 
             explicit Vector(size_type n) :std::vector<T>(n) {} 
             Vector(size_type n, const T& v) :std::vector<T>(n,v) {} 
             template <class I> 
             Vector(I first, I last) :std::vector<T>(first,last) {} 
     
            T& operator[](unsigned int i) // rather than return at(i); 
             { 
                     if (i<0||this->size()<=i) throw Range_error(i); 
                     return std::vector<T>::operator[](i); 
             } 
             const T& operator[](unsigned int i) const 
             { 
                     if (i<0||this->size()<=i) throw Range_error(i); 
                     return std::vector<T>::operator[](i); 
             } 
     
    }; 
     
    
    // disgusting macro hack to get a range checked vector: 
     #define vector Vector 
     // trivially range-checked string (no iterator checking): 
     struct String : std::string { 
     
            String() { } 
             String(const char* p) :std::string(p) {} 
             String(const string& s) :std::string(s) {} 
             template<class S> String(S s) :std::string(s) {} 
             String(int sz, char val) :std::string(sz,val) {} 
             template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) 
     { } 
     
            char& operator[](unsigned int i) // rather than return at(i); 
             { 
                     if (i<0||size()<=i) throw Range_error(i); 
                     return std::string::operator[](i); 
             } 
     
            const char& operator[](unsigned int i) const 
             { 
                     if (i<0||size()<=i) throw Range_error(i); 
                     return std::string::operator[](i); 
             } 
     
    }; 
     
    
    #ifndef _MSC_VER 
     namespace __gnu_cxx { 
         template<> struct hash<String> 
         { 
             size_t operator()(const String& s) const 
             { 
                 return hash<std::string>()(s); 
             } 
         }; 
     
    } // of namespace __gnu_cxx 
     
    
    #endif 
     struct Exit : runtime_error { 
             Exit(): runtime_error("Exit") {} 
     
    }; 
     
    
    // error() simply disguises throws: 
     inline void error(const string& s) 
     { 
             throw runtime_error(s); 
     } 
     
    
    inline void error(const string& s, const string& s2) 
     { 
             error(s+s2); 
     } 
     
    
    inline void error(const string& s, int i) 
     { 
             ostringstream os; 
             os << s <<": " << i; 
             error(os.str()); 
     } 
     
    
    #if _MSC_VER<1500 
             // disgusting macro hack to get a range checked string: 
             #define string String 
             // MS C++ 9.0 have a built-in assert for string range check 
             // and uses "std::string" in several places so that macro 
     substitution fails 
     #endif 
     template<class T> char* as_bytes(T& i)        // needed for binary I/O 
     { 
             void* addr = &i;    // get the address of the first byte 
                                                     // of memory used to store the object 
             return static_cast<char*>(addr); // treat that memory as bytes 
     
    } 
     
    
    inline void keep_window_open() 
     { 
             cin.clear(); 
             cout << "Please enter a character to exit\n"; 
             char ch; 
             cin >> ch; 
             return; 
     } 
     
    
    inline void keep_window_open(string s) 
     { 
             if (s=="") return; 
             cin.clear(); 
             cin.ignore(120,'\n'); 
             for (;;) { 
                     cout << "Please enter " << s << " to exit\n"; 
                     string ss; 
                     while (cin >> ss && ss!=s) 
                             cout << "Please enter " << s << " to exit\n"; 
                     return; 
             } 
     } 
     
    
    // error function to be used (only) until error() is introduced in 
     Chapter 5: 
     inline void simple_error(string s)      // write ``error: s   and exit 
     program 
     { 
             cerr << "error: " << s << '\n'; 
             keep_window_open();             // for some Windows environments 
             exit(1); 
     } 
     
    
    // make std::min() and std::max() accessible: 
     #undef min 
     #undef max 
     #include<iomanip> 
     inline ios_base& general(ios_base& b)   // to augment fixed and 
     scientific 
     { 
             b.setf(ios_base::fmtflags(0),ios_base::floatfield); 
             return b; 
     
    } 
     
    
    // run-time checked narrowing cast (type conversion): 
     template<class R, class A> R narrow_cast(const A& a) 
     { 
             R r = R(a); 
             if (A(r)!=a) error(string("info loss")); 
             return r; 
     } 
     
    
    inline int randint(int max) { return rand()%max; } 
     inline int randint(int min, int max) { return randint(max-min)+min; } 
     
    inline double sqrt(int x) { return sqrt(double(x)); }   // to match C+ 
     +0x 
     
    #endif




    Thanks a lot for any help in regard to this matter,
    Best regard
    Jay

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > I would put it in the C:\MinGW folder
    If this is where MinGW is installed, then you should put your code somewhere else.

    Depending on your windows operating system, say
    c:\users\you\code
    or
    c:\documents and settings\you\code

    With a suitable folder, step 2 is good.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Location
    NYC
    Posts
    2

    Smile Thanks

    It was very helpful,
    Thanks
    dbuff

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble with installing "microsoft visual c++"
    By aleminio in forum C Programming
    Replies: 3
    Last Post: 04-28-2004, 09:32 AM
  2. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  3. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21