Greetings Everyone.
I\'m currently writing a multi-language programe in C, C++ and fortran on UNIX, unfortunatly I run into \"Segmentation Error\" when I try and execute
The code you posted appears to be OK - you'll need to give more detail if you want the problem debugged. Actually, if you run the program in a debugger, it should be able to tell you exactly which line of code is causing the exception (you may have to look in a call stack), or simply step through the program until it crashes.
As for the confusion about whether vector can be treated as a C array, it definitely can by getting the address of the first element (ie., &vect[0]
) - if the vector contains elements.
The C++03 standard says this about vector<>
in 23.2.4:
The elements of a vector are stored contiguously, meaning that if
v
is avector
whereT
is some type other thanbool
, then it obeys the identity&v[n] == &v[0] + n
for all0 <= n < v.size()
Note that this was not explicitly stated in the C++98 standard (but was still the intent).
See also Herb Sutter's article:
Note that vector
cannot be treated as a C array - it a special case since the elements in vector
are not stored as bool
.