gcc - Declaring a vector in C++ throws a runtime error -


this question has answer here:

i'm trying make program involves vectors, seems though vectors won't work @ all. program looks like:

#include <vector> #include <iostream> using namespace std;  int main() {     vector <int> vec(7); //this throws error     cout << "first: " << vec.at(0) << endl;     cout << "last: " << vec.back() << endl;     vec.push_back(296);     cout << "new last: " << vec.back() << endl;     cout << "size: " << vec.size() << endl;     return 0; } 

i use gcc compile. compile not throw errors, crashes whenever run it. error get:

the procedure entry point_gxx_personality_v0 not located in dynamic link library c:\[...]\vectors.exe. 

i installed compiler , libraries via mingw , learning language c++ programming fourth edition mike mcgrath.

image:

(image)

please see http://en.cppreference.com/w/cpp/container/vector. using vector, must define this. try , there no error. in addition, first have call push_back functions , call vec.at() or vec.back(). in example, there no data in vector there fatal error.

    #include <vector>     #include <iostream>     using namespace std;          int main()         {             vector <int> vec;             vec.push_back(296);             vec.push_back(334);              cout << "first: " << vec.at(0) << endl;             cout << "last: " << vec.back() << endl;              cout << "new last: " << vec.back() << endl;             cout << "size: " << vec.size() << endl;             return 0;         } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -