Trying to determine length of a string using recursion in C++

c++, counting, recursion, string

Solution

Hint: use `substr()` in your recursion.

Also, you have two base cases. One of them has three issues:

- it has a syntax error in it;

- it relies on being able to compute the length of the string (which is what your function is supposed to do);

- it is unnecessary given that you have the other base case.

Problem

``` 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. } ``` I dont know how to traverse a string.

Original source