прекращение вызова после выброса экземпляра 'std :: length_error' what (): basic_string :: _ M_create - PullRequest
0 голосов
/ 21 октября 2019

Я пытался найти следующую ошибку, и я много поискал в интернете, но не смог решить проблему. Когда я компилирую, у меня появляется следующая ошибка

"terminate, вызываемая после создания экземпляра 'std :: length_error' what (): basic_string :: _ M_create"

Я думаю, что проблема связана сс памятью? но я не уверен, где именно проблема.

// распечатать детали, которые меняются

void print_memory(int t[],int a[],int m)
{
    output <<endl<< "Memory State:" << endl;
    for(int i=0; i<m ; i++)
    {
                output <<   "["  << a[i] << "]: "<< t[i] << endl; 
                        }
}

//print registers
remove code


void print_final_state_text(){
remove code
}

void print_final_state(){
        remove code
}

//find destination adress

int find(int arr[],int SIZE, int values) {                                          
 for (int a=0;a<40000;a++)
 {
  if(arr[a]==values)
      {
   return a;
      }
 }
}

//find register position
remove code

    void printtofile(string k){
        remove code


int main (){
//-------------TABLES------
int address[40000]={};
int timi[40000]={};
Registers[28]=268468224;
Registers[29]=2147483644;

//----------VARIABLES----
      remove code

//--------INPUT CYCLES FROM THE USER AND PRINT MESSAGES----

      remove code

//-----------------------STRUCT----------
        remove code


    input.open("test");
    output.open("pipeline");    

            int io=0,t=0;
            while(!(input.eof())){
                    ch=input.get();
                    replace(k.begin(), k.end(), '(', ' ');
                    replace(k.begin(), k.end(), ')', ' ');
                    if(ch=='b'){
                        tt++;
                    }   
                    else if(ch == '.'){
                        while(ch != '\n')
                        {
                            ch=input.get();
                           }
                        continue;
                    }
                    else if(ch == '#' ){
                            while(ch != '\n'){
                                    ch=input.get();
                                    if(input.eof()){
                                        break;
                                       }
                                        }
                                    }
                    else if(ch == '$' ){
                        continue;
                    }           
                    else if(ch == '\t'){    
                    continue;
                    }
                    else if(ch == ':'){
                    string label(k.begin(),find(k.begin(),k.end(),':'));
                    k+=ch;
                    ch=input.get();
                    while((ch=='\n') || (ch=='\t')){
                            ch=input.get();                         
                        }
                    }
                    else if(ch == ','){ 
                    continue;   
                    }   
                    if(ch =='\n' || input.eof()){               
                        if (k!=""){
                        size_t search = k.find(':');
                            if (search!=k.npos){                        
                                string label(k.begin(),find(k.begin(),k.end(),':'));
                                pointer->label=label;                           
                                string temp(find(k.begin(), k.end(), ':')+1,k.end());   
                                string opcode1(temp.begin(),find(temp.begin(), temp.end(), ' '));                                               
                                string temp2(find(k.begin(), k.end(), ' ')+1,k.end());
                                string rd1(temp2.begin(),find(temp2.begin(), temp2.end(), ' '));
                                string temp3(find(temp2.begin(), temp2.end(), ' ')+1,temp2.end());
                                string rt1(temp3.begin(),find(temp3.begin(), temp3.end(), ' '));
                                string temp4(find(temp3.begin(), temp3.end(), ' ')+1,temp3.end());
                                string rs1(temp4.begin(),find(temp4.begin(), temp4.end(), '\n'));
                                pointer->opcode_g= opcode1;
                                pointer->rd_g=rd1;
                                pointer->rt_g=rt1;
                                pointer ->rs_g=rs1;
                                pointer->pc=pccounter;
                                pccounter+=4;
                            }
                            else{
                                pointer->label="";
                                string opcode_g(k.begin(),find(k.begin(),k.end(),' '));     
                                string temp(find(k.begin(), k.end(), ' ')+1,k.end());
                                string rd_g(temp.begin(),find(temp.begin(), temp.end(), ' '));
                                string temp3(find(temp.begin(), temp.end(), ' ')+1,temp.end());
                                string rt_g(temp3.begin(),find(temp3.begin(), temp3.end(), ' '));
                                string temp4(find(temp3.begin(), temp3.end(), ' ')+1,temp3.end());
                                string rs_g(temp4.begin(),find(temp4.begin(), temp4.end(), '\n'));
                                pointer->opcode_g=opcode_g;
                                pointer->rd_g=rd_g;
                                pointer->rt_g=rt_g;     
                                pointer->rs_g=rs_g;
                                pointer->pc=pccounter;
                                pccounter+=4;
                            }   
                        pointerprevious=pointer;
                        pointer=new struct instruction;
                        pointerprevious->next=pointer;
                        pointer->next=NULL;
                        k="";                       
                        }
                        while(ch == '\n'){
                        ch=input.get();
                        }
                            if(ch == '\t'){ 
                                continue;
                            }
                    }
                    k+=ch;          
            }   
...