maverik
12/1/2008 12:35:00 PM
On Dec 1, 3:19 pm, mthread <rjk...@gmail.com> wrote:
> Hi,
> I am developing a http parser in C++. When I use the statement,
> char* data = "some string";
1. Use std::string
> I receive the warning,
> 'warning : deprecated conversion from sting constant to
> char*'
Ok. Compiler tells you that you try to convert const char* to char*
because string literal "some string" is type of const char*. Of
course, in common it's bad to convert const char* to char* because the
variable of type const char* shouldn't be changed, but using char* you
can change it.
So, complier fairly warnings you.
>
> kindly let me know why the statement is deprecated. I have just
> upgraded
> my OS(from fedora 8 to fedora 9) and I did not get the warning
> in my previous OS(fedora 8).
Probably, you complier has been upgraded with new version of distr.
> I also have a need to copy the string in character pointer as I
> do all the parsing using the data available in this pointer. I would
> also like to add that this warning is not shown when I use a 'const
> char*'(ie const char* data = "some string" ).
In your case you can try
char* data = /* memory allocation */;
strcpy(data, "some string");
/* usage of data */
....
/* free data */
Or use std::string:
std::string data = "some string"; /* Copying */