What I asked is how to copy a string,i.e. a sentence into a array of individual characters and by searching the forum I've found the c_str thing
I hope you realize that c_str is owned by the string. That is, you cannot modify it, delete the array. Furthermore, the string only exists as long as the string exists, and remains unchanged
but I'd like to improve and copy strings with spaces, because when I type a string with spaces, I only get the first part in the char array.
Can I use the getline function, if yes how in this context.
First, aren’t you storing the input in C++ strings (vs. char arrays)? Regardless, yes, you need to use getline. There’s two forms of getline. The first is the global getline from <string>. This operates on C++ strings. The second is the stream getline (e.g. cin.getline) that works with C strings. Please look up examples online, and then ask if you have any trouble understanding them.
you told me I can index a C++ string, how if I want to count the number of "a"s in a sentence ?
There’s about three ways to do this. One might be to index said string like an array (e.g. for string input, input[0], input[1], etc.). Then each element indexed is a char you can compare to ‘a’.
One C++ ish way to do would be to iterate over the string with string::iterator, checking the value to see if it were ‘a’. But what I would do is use count_if. count_if is in <algorithm>.
Actually, there's more ways to do this, but iterating with string::iterator or count_if may be the most straightforward C++ ways to do it.