473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

casting const char* to char*

13
I am writing a program in c++ using fluid with the FLTK libraries. I have a text_input widget in my main window, and when I try to access the value in the widget it returns a const char*.

I need to use this const char* as part of a filename and so I need to convert it to a char* (or some other usable form).

One guy said this is not possible in c++, but I'm assuming there must be some way to use this or else fluid would be fairly useless.

Thanks for any help you can give!
Feb 4 '09 #1
5 4660
newb16
687 512MB
copy it to std::string like
std::string myValue = widget.getValue();
and then do whatever you need with it.
Feb 4 '09 #2
JosAH
11,448 Expert 8TB
Copy the chars pointed to by that const char* to an ordinary char* and use that.

kind regards,

Jos
Feb 4 '09 #3
eranws
1
there's some mechanism called const_cast.

see this link
Feb 6 '09 #4
donbock
2,426 Expert 2GB
@eranws
Be careful with this. There might be a very important reason why it is a const pointer. For instance, if it is a pointer to read-only memory then you'll get a run-time exception if you try to write to it. The fully portable and guaranteed-to-work-no matter-what method is as JosAH suggested: allocate a large enough writeable char buffer ; copy the const buffer into it; and then use that local copy.
Feb 6 '09 #5
JosAH
11,448 Expert 8TB
The entire const business gets messier and messier; have a look at one of the latest proposals. I think Bjarne Stroustrup is on the wrong track.

kind regards,

Jos
Feb 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: wenmang | last post by:
Hi, I have a third party function that has a following signature: function(char * memoryBuffer, long bufferSize); I want to following Base64::decode() from Apache's XML C++ APIs: XMLByte*...
4
by: John Ratliff | last post by:
Say I had a three-dimensional array containing multiple 2D level data. It might be defined like this: unsigned char LEVEL_DATA = { { {1, 1, 1, 1, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1,...
33
by: Mark P | last post by:
A colleague asked me something along the lines of the following today. For some type X he has: X* px = new X; Then he wants to convert px to a char* (I'm guessing for the purpose of...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
5
by: brekehan | last post by:
I've always been a little sketchy on the differences between static, dynamic, and reinterpret casting. I am looking to clean up the following block by using C++ casting instead of the C style...
14
by: Jonas.Holmsten | last post by:
Hello I'm porting some C++ stuff to C and having problem to get it through gcc. Here is a condensed version of the problem: void foo(const int * const * const ptr) {} main()
12
by: Phil Endecott | last post by:
Dear Experts, I need a function that takes a float, swaps its endianness (htonl) in place, and returns a char* pointer to its first byte. This is one of a family of functions that prepare...
17
by: sophia.agnes | last post by:
Hi , I was going through peter van der linden's book Expert C programming, in this book there is a section named "How and why to cast" the author then says as follows (float) 3 - it's a...
5
by: jason.cipriani | last post by:
There have been some recent threads about casting pointers to and from void* that have me rethinking some of my usual practices. I have a couple of questions. 1. What is the purpose of C++'s...
10
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.