unknown error

This is a discussion on unknown error within the C++ Programming forums, part of the General Programming Boards category; the code I'm writing does compile, but when I run it through my IDE, I keep getting this error message: ...

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

    unknown error

    the code I'm writing does compile, but when I run it through my IDE,
    I keep getting this error message:

    Executable “multicalc” has exited due to signal 10 (SIGBUS).
    [Session started at 2004-12-29 11:17:36 -0500.]
    Please enter a menu option:

    Type 1 for simple calc
    Type 2 for root calc
    Type 3 for powers
    Type 4 for circumferences
    Type 5 for equations
    Type 6 for vector math
    Type 7 for help
    Type 8 to quit:
    6
    Enter vector 1, hit enter after each element, and end your last element with "L":

    Executable “multicalc” has 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 lastElement(float num){
    	
    		if(makeString(num).substr(makeString(num).length()-2,makeString(num).length()-1)=="l"){
    		
    			return true;
    			
    		}else{
    		
    			return false;
    			
    		}//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";
    		
    		while(lastElement(atof(inread[i].c_str()))==false){
    		
    			cin>>inread[i];
    			
    			i++;
    			
    		}//end while
    		
    		for(i=0;i<vector1.size();i++){
    		
    			cout<<inread[i]<<"\n";
    			
    		}//end for
    		
    	}//end vec
    	
    };//end class
    the method vec is being called from the main cpp file

    any advice?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >inread[i].c_str()
    And where do you put something in inread? i may be 0, but if the container is empty then any subscript at all is out of range.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    I found an error in my code:

    I was trying to do a substring on a conversion from a float, but the float was orginially a string, so anythign not numerical in the original string would've been lost, hence an error. I corrected it, and I still comile it perfectly, but I get errors when my IDE trys to run the program

    the new code 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 lastElement(string num){
    	
    		if(num.substr(num.length()-2,num.length()-1)=="l"){
    		
    			return true;
    			
    		}else{
    		
    			return false;
    			
    		}//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";
    		
    		while(lastElement(inread[i])==false){
    		
    			cin>>inread[i];
    			
    			i++;
    			
    		}//end while
    		
    		for(i=0;i<vector1.size();i++){
    		
    			cout<<inread[i]<<"\n";
    			
    		}//end for
    		
    	}//end vec
    	
    };//end class

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Did you just completely gloss over my reply, or was I incorrect because you didn't post enough code?
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    no, u just didn't read the code

    I add someting to inread right here:

    Code:
    while(lastElement(inread[i])==false){
                    
              cin>>inread[i];
                            
              i++;
                            
    }//end while

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Look again.

    You add something to inread right there. Right after you use it in your while expression.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >no, u just didn't read the code
    I read it. I also understood it, so I think I'm one step ahead of you. So let me say it again. You can't access an empty container. And unless you fill it through some outside force, you're accessing an empty container here:
    Code:
    while(lastElement(inread[i])==false){
    Unless, of course, the rules of C++ have changed and the first line of your loop is executed before the loop condition.
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Quote Originally Posted by Prelude
    Unless, of course, the rules of C++ have changed and the first line of your loop is executed before the loop condition.
    Didn't you get the memo?

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    OOOHHHHH...

    sry, my bad, with the conditions i used I should have put a do while statement instead of a while

    oops

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21