lecture 문제에 대해 질문 드립니다.

  • wndusgh21
    wndusgh21

    RTE (SIGABRT: program aborted, probably assertion fail)
    위와 같은 오류가 발생하는데요. 나름 에러날 곳을 다 찾아 보았지만 못 찾겠더군요.
    한번 보시고 도움부탁 드리겠습니다.

    LECTURE

    #include<iostream>
    #include<vector>
    #include<algorithm>
    
    
    struct str{
        char first;
        char second;
    
        str(char a, char b){
            first=a;
            second=b;
        }
    };
    
    bool pCompare(const str& a, const str& b)
    {  
        if(a.first==b.first)
            return a.second<b.second;
        else
            return a.first<b.first;
    }
    
    
    int main()
    {
        int testcase;
        char inputString[1001];
        std::vector<str> st;
    
        std::cin>>testcase;
    
        while(testcase--){
    
            for(int i=0; i<1001; i++)           //초기화
                inputString[i]=0;
    
            std::cin>>inputString;  
    
            for(int i=0;;i+=2)
            { 
                if(inputString[i] == 0)
                    break;
    
                st.push_back(str(inputString[i],inputString[i+1]));
            } 
    
            std::sort(st.begin(),st.end(),pCompare);
    
            for(int i=0; i<st.size(); i++)
                std::cout<<st[i].first<<st[i].second;
    
            std::cout<<std::endl;
    
            st.clear();
        }
    
        st.~vector<str>();
    
        return 0;
    }
    

    11년 전
2개의 댓글이 있습니다.
  • Being
    Being

    맨 끝에 destructor를 명시적으로 호출하고 있는데, 이렇게 하는 경우 destructor가 두 번 호출되게 됩니다. 이 과정에서 문제가 생긴 것으로 보이며, destructor를 명시적으로 호출하는 용법은 사실상 거의 사용되지 않습니다.


    11년 전 link
  • wndusgh21
    wndusgh21

    @Being 감사합니다. 제가 어디서 메모리반환 해야된다고 보고 게속 써왔었는데 저것이 잘못된 것이었군요.....
    알려주셔서 감사합니다. 제거하니 바로 정답이 뜨네요.
    감사합니다!!


    11년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.