前提・実現したいこと
C++のSegmentation Faultのデバッグ
発生している問題・エラーメッセージ
Segmentation fault: 11
該当のソースコード
#include<iostream> #include<stack> #include<algorithm> #include<string> #include<vector> using namespace std; int main(){ stack<int> S1; stack<pair<int,int> > S2; int sum = 0; char temp; int counter = 1; while(1){ cin >> temp; if(temp == '\') S1.push(counter); else if(temp == '/'){ int j = S1.top(); S1.pop(); sum += counter-j; int a = counter-j; while(S2.top().first > j && S2.size() > 0){ a += S2.top().second; S2.pop(); } S2.push(make_pair(j,a)); }else if(temp == 'q'){ break; } counter += 1; } vector<int> ans; while(S2.size()>0){ ans.push_back(S2.top().second); S2.pop(); } cout << sum << endl; cout << ans.size() << endl; for(int i=0;i<ans.size();i++){ cout << " " <<ans[i]; } return 0; }
試したこと
while(1)内のelse ifに差し掛かったところでSegmentation Faultが出ているようなのですが、それ以上分からず、大変お手数ですがどなたかお助け下さい。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。