Ansistring -> cstring, lose a letter?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpenguin
    New Member
    • Aug 2007
    • 41

    Ansistring -> cstring, lose a letter?

    I'm writing an MCF prog, and I need to convert an ansistring to a cstring, but it seems to lose the last letter--

    Code:
    char* S = input->Text.c_str();
       Label1->Caption = S;
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by jpenguin
    I'm writing an MCF prog, and I need to convert an ansistring to a cstring, but it seems to lose the last letter--

    Code:
    char* S = input->Text.c_str();
       Label1->Caption = S;
    Did u try to print the value holded by the variable S?
    I dont think it will truncate the character.
    Check what value input(variable) is holding

    Raghuram

    Comment

    • jpenguin
      New Member
      • Aug 2007
      • 41

      #3
      yep, when I print S it dosent matter how many letters I put inn the first string it cuts off the last letter.

      I am using Boreland C++ builder, can I send you my build directory?

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by jpenguin
        yep, when I print S it dosent matter how many letters I put inn the first string it cuts off the last letter.

        I am using Boreland C++ builder, can I send you my build directory?

        I have only Cygwin with g++ in my system.
        My be other members who have borland can help you

        Raghuram

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by jpenguin
          char* S = input->Text.c_str() ;
          Label1->Caption = S;
          This is ssuspicious code.

          First, the c_str() returns a const char* and this cannot be assign to a char*. So you are getting a compiler error here. That is, your code won't compile. If it won't compile, you can't be running it.

          If you are not getting an error, I suggest you get a better C++ compiler.

          Comment

          Working...