#26244: 請問這是甚麼意思:系統呼叫了 abort 函式! *** stack smashing detected ***: terminated aborted (core dumped)


s910306@hlhs.hlc.edu.tw (潘廌宥10932)

學校 : 不指定學校
編號 : 159003
來源 : [223.139.88.103]
最後登入時間 :
2021-07-26 20:54:08
a009. 解碼器 -- ACM 458 | From: [223.139.88.104] | 發表日期 : 2021-07-26 20:37

請問這是甚麼意思:系統呼叫了 abort 函式! *** stack smashing detected ***: terminated aborted (core dumped)

下面是我寫的程式:

#include <iostream>

#include<string>

using namespace std;

int main() {

string s;

string a;

while(cin>>s){ 

for(int i=0; i<s.size();i++){

 

a[i]=s[i]-7;

cout<<a[i];

}

cout<<endl;

}

return 0;

}

 

 

 
#26294: Re:請問這是甚麼意思:系統呼叫了 abort 函式! *** stack smashing detected ***: terminated aborted (core dumped)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a009. 解碼器 -- ACM 458 | From: [39.10.131.149] | 發表日期 : 2021-07-31 15:12

請問這是甚麼意思:系統呼叫了 abort 函式! *** stack smashing detected ***: terminated aborted (core dumped)

下面是我寫的程式:

#include

#include

using namespace std;

int main() {

string s;

string a;

while(cin>>s){ 

for(int i=0; i<s.size();i++){

 

a[i]=s[i]-7;

cout<<a[i];

}

cout<<endl;

}

return 0;

}

 

 

string 不是這樣用的...會出現錯誤應該是 a 是空的,a[i] 根本不存在。
你可以不需要用 a,直接 cout<<char(s[i]-7),或者把 string a 改成 char a 然後 a[i] 改成 a 也可,不過就有點多此一舉了

 

 
ZeroJudge Forum