int count(string s){
if(s == "")
return 0;
if(s.length == 1)
return 1;
return 1 + count() //This is what I can't figure out. How to traverse the string.
//I just need a hint, not a full on answer.
}
我不知道如何遍歷字符串。嘗試確定在C++中使用遞歸的字符串的長度
提示:字符串的大小是1 +刪除第一個(或最後一個)字符的字符串的大小。空字符串的大小爲零。 – zackg
聽起來像作業給我..現在你可能想要在第二行最後一行:return 1 + count(s.substr(0,s.length() - 1)); – Nils
是的,它是功課。沒什麼特別的,但是它讓我很好。 –