• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 611
  • Last Modified:

'const char *' to 'char *'

Hi Experts,


 char* pszFind = strstr(CStr()+uStartIndex, pSzSearch);

I got the following error :

cannot convert from 'const char *' to 'char *'

I need help tp resolve this problem ?

Thanks,
0
bachra04
Asked:
bachra04
1 Solution
 
jkrCommented:
I don't knw which of the parameters the compiler complains about (since all input parameters to 'strstr()' usually are 'const char*'), but maybe a 'const_cast<char*>()' can help, see http://www.cprogramming.com/reference/typecasting/constcast.html
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I don't think the problem is with what strstr is expecting, I think the issue is just with the part...

CStr()+uStartIndex

Open in new window


What are you trying to achieve with this? It doesn't really make sense.
0
 
Infinity08Commented:
Try changing that to :

const char* pszFind = strstr(CStr()+uStartIndex, pSzSearch);

Open in new window

0
 
bachra04Author Commented:
Hi infinity08,

Yes it compiles like you suggested, I just have one question is :

this is the rest of the code , is that safe to convert it to const char* :

 if (pszFind != NULL)
    {
        uIndex = pszFind - CStr();
    }
0
 
Infinity08Commented:
If uIndex is a const char*, that should be ok, yes.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now