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

string concatenation

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
4 Posts 4 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.
  • H Offline
    H Offline
    harishkharvi
    wrote on last edited by
    #1

    i want to know how to concatenate two string (Eg: str1 & str2)

    C N S 3 Replies Last reply
    0
    • H harishkharvi

      i want to know how to concatenate two string (Eg: str1 & str2)

      N Offline
      N Offline
      NeoAks007
      wrote on last edited by
      #2

      Hi Harish, You could use strcat function provided in string.h to concatenate 2 strings. e.g strcat(str1,str2) concatenates str2 with str1.

      1 Reply Last reply
      0
      • H harishkharvi

        i want to know how to concatenate two string (Eg: str1 & str2)

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Which kind of string ? C style strings ? Then use strcat. std::string ? Then use the + operator.

        Cédric Moonen Software developer
        Charting control [v1.5] OpenGL game tutorial in C++

        1 Reply Last reply
        0
        • H harishkharvi

          i want to know how to concatenate two string (Eg: str1 & str2)

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Use std::string or CString and then you can do it like this:

          std::string a = "Hello ";
          std::string b = "World";

          std::string c = a + b;

          or

          CString a = "Hello ";
          CString b = "World";

          CString c = a + b;

          Otherwise, if you just use C strings, you have to do stuff like this:

          char a[10];
          char b[10];
          char c[20];
          strcpy(a, "Hello ");
          strcpy(b, "World");
          strcpy(c, b);
          strcat(c, a);

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          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