Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString Concatenation question

CString Concatenation question

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi I am trying to concatenate a number of CString, problem is After the third it includes the NULL termination which delimits the string. Let me post the code b_command, prog_location, end_addr and casid2 are all of type CString

    int starters = strtol(prog_location,&hold_ptr,16);
    int enders = starters + progsize;
    _itoa(enders,p = end_addr.GetBuffer(0),16);

    b_command = b_command + prog_location + "-" + end_addr + " " + casid2;

    b_command, prog_location, end_addr, and casid2 are all strings After b_commnd = ..... the string containing end_addr has the NULL marker included in b_command making the data casid2 invisible I can see that casid2 is there after the NULL by looking in memory

    J 1 Reply Last reply
    0
    • F ForNow

      Hi I am trying to concatenate a number of CString, problem is After the third it includes the NULL termination which delimits the string. Let me post the code b_command, prog_location, end_addr and casid2 are all of type CString

      int starters = strtol(prog_location,&hold_ptr,16);
      int enders = starters + progsize;
      _itoa(enders,p = end_addr.GetBuffer(0),16);

      b_command = b_command + prog_location + "-" + end_addr + " " + casid2;

      b_command, prog_location, end_addr, and casid2 are all strings After b_commnd = ..... the string containing end_addr has the NULL marker included in b_command making the data casid2 invisible I can see that casid2 is there after the NULL by looking in memory

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You must call ReleaseBuffer() after changing the string. While not doing so the CString object may be in an undefined state. See CSimpleStringT::GetBuffer[^]:

      Quote:

      If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before you use any other CSimpleStringT member methods.

      So use:

      _itoa(enders,p = end_addr.GetBuffer(0),16);
      end_addr.ReleaseBuffer();

      F S 2 Replies Last reply
      0
      • J Jochen Arndt

        You must call ReleaseBuffer() after changing the string. While not doing so the CString object may be in an undefined state. See CSimpleStringT::GetBuffer[^]:

        Quote:

        If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before you use any other CSimpleStringT member methods.

        So use:

        _itoa(enders,p = end_addr.GetBuffer(0),16);
        end_addr.ReleaseBuffer();

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        worked :) Thanks

        1 Reply Last reply
        0
        • J Jochen Arndt

          You must call ReleaseBuffer() after changing the string. While not doing so the CString object may be in an undefined state. See CSimpleStringT::GetBuffer[^]:

          Quote:

          If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before you use any other CSimpleStringT member methods.

          So use:

          _itoa(enders,p = end_addr.GetBuffer(0),16);
          end_addr.ReleaseBuffer();

          S Offline
          S Offline
          Saravanan Sundaresan
          wrote on last edited by
          #4

          :thumbsup:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups