ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
i m sorry but i forgot to tell about the error message..
in the function defination
u see that i have declared
const char* x;
if i deleted the const word ,the error will appear..
invalid conversion from const char* to char*
Since you're using C++ I strongly recommend std::string instead of char* or const char*. You can always pass an std::string.c_str() to library functions which need const char* arguments and it's much less hassle to use std::string in all your programs since you needn't allocate and deallocate memory each time like you do for char*.
edit: since you're already using namespace std, it should be a matter of just declaring it as
string a_str = "A string";
Last edited by vharishankar; 08-04-2006 at 07:42 AM.
You declared current as const char* so you have to declare x also as const, because there is no impicite conversion from const char* to char* (exactly what the error message told you). If you necessarily need to assign a "const" to a "non-const", then you can use the explicite convert operator const_cast:
const char *current;
x = const_cast<char*>(current);
But be careful; very often you should consider to change your design instead of using const_cast. You may also want to go through some tutorials about type casting as well as the const modfier in C++. Simply ask google for these words.
PS. And as Harishankar said already: You should consider to use std::string
Const correctness is a good thing. You are making a promise that you are not going to modify the stuff something points to, etc. So either you keep the promise, or you don't make it in the first place. What's so hard about that?
but call: meta_data::decode_int( const char* current ,int* charecter_lenght , long* integer )
and get: invalid conversion from `const char*' to `char*'
and for me it should be: invalid conversion from `char*' to `const char*'
It should not be a proble with const char to char but a problem with char to const char.
No, you can always do that. Do you understand what the const means? "const char *" means you cannot do anything that can modify the things pointed to by the pointer, which is more restrictive than "char *", so it's always okay to convert from "char *" to "const char *", but not the other way.