Hi, in the Palindrome challenge I had to check the solution from the beginning because I didn´t know how to treat the string.
Is a string treated like a vector of characters?
If that´s the case, why can we use ‘+’ to add characters instead of using .push_back?
Can somebody point me to the lesson where all of this stuff about strings is explained previously in order to be able to solve the challenge without watching the solution? Thank you.
A string is an abstraction of an array of characters.
We use operators like + because we want to treat a string like a string, not a container. That is why the abstraction exists.
Working with a string should sound like english. "Hey Add the text ’ world’ to that ‘hello’ "
We wouldn’t say push that text back there. push_back makes sense if you think of a container, push this box to the back of the container.
I see, makes sense…but in which lesson is all of this explained? The vector lesson talks about the .size() method but I couldn´t find anything related to strings.
Don’t know, or if it even is.
The big takeaway is a String is a String, a Vector is a Vector
A String is a type with methods to work on its data - it defines a + operator to add more chars
A Vector is a type designed to hold other types it has it’s own methods to do things with its data
A Vector holds a bunch of strings
Vector defines push_back to add more strings
You could add a string to a vector and also add chars to that string in the vector
Ok, thank you…but I don´t think it makes sense to ask to solve a problem with knowledge that hasn´t been explained previously, this last exercise should be changed or deleted unless the knowledge required to solve it is explained in a previous lesson of this same course.