ccplusplus.com
Learn C, C++ Concepts
Saturday, May 5, 2012
Error Handling in STL c++
/******************************************************************* * File : error-handling-stl.cpp * Author : Team ccplusplus * Description : Error Handling in STL * Date : PM 08:58 05 May 2012 * Source : http://www.ccplusplus.com/p/c_15.html * Note : this program has error in it. *******************************************************************/ #include
#include
#include
using namespace std; int main() { vector
coll1; //empty collection vector
coll2; //empty collection /* * RUNTIME ERROR: beginning is behind the end of the range */ vector
::iterator pos = coll1.begin(); reverse (++pos, coll1 .end()); //insert elements from 1 to 9 into coll2 for (int i=1; i<=9; ++i) { coll2.push_back (i); } /*RUNTIME ERROR: overwriting nonexisting elements */ copy (coll2.begin(), coll2.end(), //source coll1 .begin()) ; //destination /* RUNTIME ERROR: * - collections mistaken * - begin() and end() mistaken */ copy (coll1.begin(), coll2.end(), //source coll1. end()); //destination return 0; } /* * * [blog@ccplusplus error-handling]$ c++ -c error-handling-stl.cpp [blog@ccplusplus error-handling]$ c++ -o error-handling-stl error-handling-stl.o [blog@ccplusplus error-handling]$ ./error-handling-stl Segmentation fault (core dumped) [blog@ccplusplus error-handling]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment