I have the below mentioned function in a large piece of code(in c++):
void startup(const char *& start,
const char *& stop);
After this function has been called I want to access the character values i.e string stored between ‘start’ and ‘stop’.
The way I am trying to access the same is:
char *var=(c.start);
cout<<"\n Iterating over char pointer \n";
while(var<=(c.stop))
{
cout<<*var;
var++;
}
cout<<"\n";
However, while trying to access it this way I am getting the below mentioned error:
error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
Can someone be kind enough to rectify the error…and help me access the character values
All you need to do is replace the line:
with:
Note that that
constrefers to the character pointed to by the pointer, not the pointer itself. So an expression likevar++is perfectly fine, since the pointer isn’t const.