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 Class Operations

String Class Operations

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
10 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.
  • A Offline
    A Offline
    Aidman
    wrote on last edited by
    #1

    Is it possible to create a string/char-array class with overloading operations that could preformed these operations?: String = “Hello ” + “World”; Where two constant strings/char-arrays “Hello ” and “World” adds and inserts into the String class. So that the class String will contain the string/char-array "Hello World". Aidman » over and out

    N 1 Reply Last reply
    0
    • A Aidman

      Is it possible to create a string/char-array class with overloading operations that could preformed these operations?: String = “Hello ” + “World”; Where two constant strings/char-arrays “Hello ” and “World” adds and inserts into the String class. So that the class String will contain the string/char-array "Hello World". Aidman » over and out

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      You could use CString (now available for both MFC and ATL) Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      A 1 Reply Last reply
      0
      • N Nish Nishant

        You could use CString (now available for both MFC and ATL) Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

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

        Yes I know... but it would be nice to know that this syntax is possible in pure C++ :) Aidman » over and out

        N M 2 Replies Last reply
        0
        • A Aidman

          Yes I know... but it would be nice to know that this syntax is possible in pure C++ :) Aidman » over and out

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Aidman wrote: but it would be nice to know that this syntax is possible in pure C++ Yes, it is very much possible. You just have to overload the + operator and the += operator. In fact taking a look at the CString source might help you. There are also some very good non-MFC CString-type classes here on CodeProject. Regards, Nish


          Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

          1 Reply Last reply
          0
          • A Aidman

            Yes I know... but it would be nice to know that this syntax is possible in pure C++ :) Aidman » over and out

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

            What do you mean by "pure C++"? If I get your question, the answer is no, you cannot overload + to concatenate two char arrays. At least one argument must be a user-defined type. --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

            A 1 Reply Last reply
            0
            • M Michael Dunn

              What do you mean by "pure C++"? If I get your question, the answer is no, you cannot overload + to concatenate two char arrays. At least one argument must be a user-defined type. --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

              A Offline
              A Offline
              Aidman
              wrote on last edited by
              #6

              Michael Dunn wrote: What do you mean by "pure C++"? What I mean is if it possible to create a class with C++ syntax (non-MFC) that could preform exactly the following operation: String = "Hello " + "World"; Michael Dunn wrote: If I get your question, the answer is no, you cannot overload + to concatenate two char arrays. At least one argument must be a user-defined type. But can cString preform this operation? Meaning can cString do this?: String = "Hello " + "World"; If so then why can cString do it and not a custom class? Aidman » over and out

              M 1 Reply Last reply
              0
              • A Aidman

                Michael Dunn wrote: What do you mean by "pure C++"? What I mean is if it possible to create a class with C++ syntax (non-MFC) that could preform exactly the following operation: String = "Hello " + "World"; Michael Dunn wrote: If I get your question, the answer is no, you cannot overload + to concatenate two char arrays. At least one argument must be a user-defined type. But can cString preform this operation? Meaning can cString do this?: String = "Hello " + "World"; If so then why can cString do it and not a custom class? Aidman » over and out

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

                Aidman wrote: What I mean is if it possible to create a class with C++ syntax (non-MFC) that could preform exactly the following operation: String = "Hello " + "World"; No, read my previous post again for why this is not possible. --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

                A 1 Reply Last reply
                0
                • M Michael Dunn

                  Aidman wrote: What I mean is if it possible to create a class with C++ syntax (non-MFC) that could preform exactly the following operation: String = "Hello " + "World"; No, read my previous post again for why this is not possible. --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

                  A Offline
                  A Offline
                  Aidman
                  wrote on last edited by
                  #8

                  Ok, but can cString preform this operation? Aidman » over and out

                  N 1 Reply Last reply
                  0
                  • A Aidman

                    Ok, but can cString preform this operation? Aidman » over and out

                    N Offline
                    N Offline
                    Nish Nishant
                    wrote on last edited by
                    #9

                    Aidman wrote: Ok, but can cString preform this operation? Nope. You can add a CString and a character pointer, but you cannot add two character pointers :-) Nish


                    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                    A 1 Reply Last reply
                    0
                    • N Nish Nishant

                      Aidman wrote: Ok, but can cString preform this operation? Nope. You can add a CString and a character pointer, but you cannot add two character pointers :-) Nish


                      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                      A Offline
                      A Offline
                      Aidman
                      wrote on last edited by
                      #10

                      Ok Thanks :) Aidman » over and out

                      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