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. simple string concatenation question

simple string concatenation question

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
8 Posts 6 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.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    Hi guys, I am trying to add double slashes in front of a string, I am wondering it can be done as below Assuming both variables have contained some characters char *FileString; // a pointer to character string char Buffer[256]; // an array to 256 characters FileString = '//' + Buffer; Please advise, Thanks alot

    N A M B 4 Replies Last reply
    0
    • J J B 0

      Hi guys, I am trying to add double slashes in front of a string, I am wondering it can be done as below Assuming both variables have contained some characters char *FileString; // a pointer to character string char Buffer[256]; // an array to 256 characters FileString = '//' + Buffer; Please advise, Thanks alot

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      Use strcat() -Nick Parker

      J 1 Reply Last reply
      0
      • J J B 0

        Hi guys, I am trying to add double slashes in front of a string, I am wondering it can be done as below Assuming both variables have contained some characters char *FileString; // a pointer to character string char Buffer[256]; // an array to 256 characters FileString = '//' + Buffer; Please advise, Thanks alot

        A Offline
        A Offline
        anju
        wrote on last edited by
        #3

        U can try like this. CString strFileString; CString strSlah("//"); char szBuffer[256]; strFileString=strSlash+szBuffer; regards anju anju

        1 Reply Last reply
        0
        • J J B 0

          Hi guys, I am trying to add double slashes in front of a string, I am wondering it can be done as below Assuming both variables have contained some characters char *FileString; // a pointer to character string char Buffer[256]; // an array to 256 characters FileString = '//' + Buffer; Please advise, Thanks alot

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          C-style strings don't work like that. You should be using std::string unless there is an overriding reason not to:

          std::string FileString;
          std::string Buffer = "some stuff...";

          FileString = "//" + Buffer;

          --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

          J 1 Reply Last reply
          0
          • M Michael Dunn

            C-style strings don't work like that. You should be using std::string unless there is an overriding reason not to:

            std::string FileString;
            std::string Buffer = "some stuff...";

            FileString = "//" + Buffer;

            --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

            J Offline
            J Offline
            J B 0
            wrote on last edited by
            #5

            Thanks guys, I tried not to use std::string as I am not sure if it's portable to Embedded Visual C++. I am doing the program using Visual C++ and expecting to make it workable on iPAQ when re-compling.

            A 1 Reply Last reply
            0
            • J J B 0

              Thanks guys, I tried not to use std::string as I am not sure if it's portable to Embedded Visual C++. I am doing the program using Visual C++ and expecting to make it workable on iPAQ when re-compling.

              A Offline
              A Offline
              Anders Molin
              wrote on last edited by
              #6

              AFAIR STL is not avaliable in eMbedded Visual C++ - Anders Money talks, but all mine ever says is "Goodbye!"

              1 Reply Last reply
              0
              • N Nick Parker

                Use strcat() -Nick Parker

                J Offline
                J Offline
                J B 0
                wrote on last edited by
                #7

                strcat() won't work as it accepts only constant char* , which buffer[] isn't. It crashes the program upon that point. e.g. char string[200] strcpy(string, "\\"); strcat(string, Buffer); <-- won't work here. Any suggestions? Thanks again

                1 Reply Last reply
                0
                • J J B 0

                  Hi guys, I am trying to add double slashes in front of a string, I am wondering it can be done as below Assuming both variables have contained some characters char *FileString; // a pointer to character string char Buffer[256]; // an array to 256 characters FileString = '//' + Buffer; Please advise, Thanks alot

                  B Offline
                  B Offline
                  Brian Shifrin
                  wrote on last edited by
                  #8

                  strcpy(FileString, "//"); strcat(FileString, (char *) Buffer); Brian

                  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