char *here = "hello there whats up";
//&here[20] = '\0'; this does not work! 20 is the position after p
cout<<here<<" ****"<<endl;
cout<<&here[5]<<" **test**"<<endl;
1. How can i add a char '\0' after the letter p?
2. How can i add a termination char '\0' in the middle of the string?
This a sample example. Don't worry about the for loop, etc.
>>Why would you want to add '\0' after the last character?
I mainly asked to know how to place \0 in a middle a string. I think i have to use memmov()
>>The pointer isn't constant,
Right, its not constant...
>>it is the object (in this case the text string literal) that is constant (which is why you can't modify it).
1. Is string in C++ immutable?
2. I would agree with this statement that the text is object if the text stored in a variable declared as string, not char * since char does not have member functions you can call such as .size(), etc. Can you clarify your statement more please.
when you declare and initialize the pointer same time the string is constant and hence you cant change the value. so this way you can take a pointe. either you have to take string as Bazzy said or else you have to allocate memory using malloc.