This is how I would have done it, and how I think he wants you to do it.
1 2 3 4
|
string name;
cin >> name;
cout << name.substr(1, name.length() - 2) << endl;
|
a string works like an array. If I enter Tarik as my name. What will be printed out is ari, this is why.
the substring function takes 2 parameters. Where to start, and for how many characters to go. Remember it's like an array, so by starting at 1 and not 0, we jump over the first letter, so that's gone now. Now we want the last letter gone.
If I type in the name Tarik, then
name.lenght()
will be equal to 5, because Tarik is 5 characters.
So when the second parameter is
name.lenght() - 2
will be equal to 3. Meaning, we want it to start at 1 and go on for 3 characters.
Tarik becomes ari. Starts at the second letter 1, goes on for 3 letters a,r,i.
This way, using the lenght function it works for all words, try it out for yourself. The way you did it
cout << name.substr(1, 12) << endl;
Doesn't work for all words, only for those that are 13 characters exactly, no more no less.