Thread: "exited due to signal 10 (sigbus)"

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    "exited due to signal 10 (sigbus)"

    the code I'm using is:

    Code:
    //vect.h
    //does vector math
    
    #include <iostream>
    #include <string>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <sstream>
    
    using namespace std;
    using std::string;
    
    class vect {
    public:
    
    	vector <float> vector1;
    	vector <float> vector2;
    	string vectorsWhole[2];
    	vector <string> inread;
    	bool last;
    	int choice;
    	int vectIndex[2];
    	char func;
    	float scalar;
    	vector <float> vectorEQ;
    	
    	bool notLastElement(string num){
    	
    		if(num.substr(num.length()-2,num.length()-1)=="l"){
    		
    			return false;
    			
    		}else{
    		
    			return true;
    			
    		}//end if
    		
    	}//end last element
    	
    	void vec(){
    	
    		int i=0;
    	
    		cout<<"Enter vector 1, hit enter after each element, and end your last element with \"L\":\n";
    		
    		do{
    		
    			cin>>inread[i];
    			
    			i++;
    			
    		}while(notLastElement(inread[i]));
    		
    		for(i=0;i<vector1.size();i++){
    		
    			cout<<inread[i]<<"\n";
    			
    		}//end for
    		
    	}//end vec
    	
    };//end class
    the only thing that has to do with this code in the main cpp file is the calling of method vec

    as I said in the title, as soon as vec is called, there's about a 5 second delay where you can enter data and then it "exits due to signal 10 (sigbus)"

    any help

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >cin>>inread[i];
    >}while(notLastElement(inread[i]));
    We went over this before, and it's the same problem with a different disguise. You can't access nonexistent elements of a vector. Because inread is an empty vector, using the subscript operator will always fail and after you increment i, you're still looking out into limbo. Since you're adding items to the end in a linear fashion, do this instead:
    Code:
    string in;
    
    do {
      cin>> in;
      inread.push_back(in);
    } while (notLastElement(in));
    [edit]
    On a side note, because this seems to be such an issue with you, you should be using the at member function of vector for subscripting. That way it will throw an exception if you're out of bounds rather than crash with an access violation.
    [/edit]

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    thanx
    I wasn't aware that adding to a vector added it to the end, my bad

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation Fault
    By Lost__Soul in forum C Programming
    Replies: 46
    Last Post: 04-28-2003, 04:24 AM
  2. how to handle integer overflow in C
    By kate1234 in forum C Programming
    Replies: 8
    Last Post: 04-23-2003, 12:20 PM
  3. Scheduling Algo
    By BigDaddyDrew in forum C++ Programming
    Replies: 41
    Last Post: 03-08-2003, 11:00 AM
  4. Heaps...
    By Nutshell in forum C Programming
    Replies: 14
    Last Post: 04-23-2002, 08:54 AM
  5. Formatting Output
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 03-26-2002, 01:33 AM