Can somebody please tell me why I am getting a segmentation fault in the following piece of code, I have marked the spot that gdb is telling me it is occuring at.
vector<int> F;
vector<int> F2;
vector<int> F1;
vector<int> temp;
F2.push_back(1);
F1.push_back(1);
for(int i=2; i<=question; ++i){
cout<<"I am at Line"<<__LINE__<<endl;
F=(bin.add(F1,F2));
F2.clear();
F2.swap(F1);
F1.swap(F);
temp=bin.bintodec(F1);
cout<<"This is this ";
vector<int>::iterator it;
cout<<"The size is "<<temp.size();
for(it=(temp.end()); it>=temp.begin(); --it){
cout<<*it;//THIS IS WHERE THE SEG FAULT IS OCCURING
}
Thank you for your help, and if you need more of the code to tell, please let me know.
david@david-laptop:~/Desktop/Cs315/binary$ gdb ./a.outGNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty"for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/david/Desktop/Cs315/binary/a.out...done.
(gdb) run
Starting program: /home/david/Desktop/Cs315/binary/a.out
what is the index that you are wanting to find the fibrinacci number of?
2
I am at Line30
A[i]=1B[i]=1The Carry Is0
The Sum Is2
1
Program received signal SIGSEGV, Segmentation fault.
0x08048cb5 in fibro::findfibro (this=0xbffff388) at fibro.cc:40
40 cout<<*it;
(gdb) backtrace
#0 0x08048cb5 in fibro::findfibro (this=0xbffff388) at fibro.cc:40
#1 0x0804a3f3 in main () at fibroDriver.cc:10
(gdb) quit
A debugging session is active.
Inferior 1 [process 2927] will be killed.
Quit anyway? (y or n) y
You're trying to dereference temp.rend(), which is one before the first element. Actually, you're decrementing the reverse iterator, causing it to point to one past the last element. That's two things you need to fix.