I have this code and it has problem.
using namespace std;
When you declare char str you are declaring an array of chars (which is accessible to be both read and written), and this array is initialized to some sequence of characters i.e. "This is test string" is copied to the elements in this array.
When you declare char* str, you are declaring a pointer that points directly to some constant literal - not a copy. These can only be read.