FLTK logo

[fltk.general] Re: Why do I need to convert a string to a string for Fl_Input

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Why do I need to convert a string to a string for Fl_Input Ian MacArthur Oct 06, 2022  
 
On Wednesday, 5 October 2022 at 23:40:12 UTC+1 roger wrote:
 
  string s1 = to_string(z);
  string s2 = s1.c_str();
// win2_unitprice->value(s1);
    win2_unitprice->value(s1.c_str());

If I uncomment line 3 I get the following error:-
error: no matching function for call to ‘Fl_Input::value(std::__cxx11::string&)’
   win2_unitprice->value(s1);

but if i look at the data I see that:-
s1 holds the address of the data 0x31 0x2e 0x31 0x30 ....
and 
s2 holds the address of the data 0x31 0x2e 0x31 0x30 ....

so why do I need to use c_str() to make this work ??

Not at all clear what you think s2 is doing here? You declare and set it but do not appear to use it?

In any case, the "answer" to your question is that Fl_Input::value() does not take a "string" in the C++ sense, it takes a pointer to an array of characters; which is often referred to as a "string" in the C-sense, but is a different animal.

The fltk API was (in large part, anyway) originally inherited form a previous, proprietary, lib called "Forms" which was a C lib, and presented a C API. In consequence, much of fltk also presents a fairly C-like API. Which often aids portability, but may seem archaic now...

A C++ "string" is an object which holds a string of text; the actual content is notionally opaque, but it probably does hold an array of characters, along with various attributes about the string, such as length and so on, and methods to manipulate that data.

A C "string" is just a sequence of bytes that ends in a zero - you don't even know how long it is unless you count 'em.

The C++ object is a much less error-prone entity, but that's a whole other story.
Welcome to the world of C-programming...

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/2789cbd6-e299-4ec0-b268-9fa9f0c750a2n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.