我認爲這個錯誤與我的字符串太大有關。如果該功能正常工作,我懷疑我會接近最大字符串大小(除非真的是這個問題?我懷疑它是因爲這是用於硬件分配,我們需要返回output
與歌詞)。什麼是拋出這個錯誤?字符串有多大?C++中的字符串類有多大?
錯誤:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Aborted (core dumped)
職能:list[]
string generateSong(string list[], int num)
{
string output;
for(int count = 0; count <= num; count++)
output += list[count] + " bone connected to the "
+ list[count + 1] + " bone\n";
return output;
}
內容:
string list[9] =
{
"toe",
"foot",
"leg",
"knee",
"hip",
"back",
"neck",
"jaw",
"head"
};
num
是9.是output
真的變得太大了?一切都很好(使用g ++)。
是否'名單[]'有11款產品? –
'list []'包含9個項目。我會把這些項目放在OP中。 –
迭代至count
Pramod