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. i have problem with CString please help me

i have problem with CString please help me

Scheduled Pinned Locked Moved C / C++ / MFC
helpperformancequestion
12 Posts 7 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.
  • R rajneshmalik

    hi all i want to allocate memory for two diamentional sring like CString mydata=new CString[10]; for "TWO DIAMENTION". I done CString mydata=new CString[10][10]; but compiler raise error how can i solve this problem; thank u in advance malik

    N Offline
    N Offline
    Neo Andreson
    wrote on last edited by
    #2

    Try with this CString *mydata=new CString[10];

    N 1 Reply Last reply
    0
    • R rajneshmalik

      hi all i want to allocate memory for two diamentional sring like CString mydata=new CString[10]; for "TWO DIAMENTION". I done CString mydata=new CString[10][10]; but compiler raise error how can i solve this problem; thank u in advance malik

      P Offline
      P Offline
      Paresh Chitte
      wrote on last edited by
      #3

      What is your requirement ? Will CStringArray helpful ? Regards, Paresh.

      1 Reply Last reply
      0
      • R rajneshmalik

        hi all i want to allocate memory for two diamentional sring like CString mydata=new CString[10]; for "TWO DIAMENTION". I done CString mydata=new CString[10][10]; but compiler raise error how can i solve this problem; thank u in advance malik

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #4

        rajneshmalik wrote:

        I done CString mydata=new CString[10][10];

        Two dimension array cannot be created like this. You have to do like

            CString** pStr = new CString* [10];
            for( int i = 0; i < 10; i++ )
                pStr[i] = new CString[10];
        

        - NS -

        R 1 Reply Last reply
        0
        • N Neo Andreson

          Try with this CString *mydata=new CString[10];

          N Offline
          N Offline
          Neo Andreson
          wrote on last edited by
          #5

          Sorry this is wrong, u have to use CStringArray Class

          K 1 Reply Last reply
          0
          • N Neo Andreson

            Sorry this is wrong, u have to use CStringArray Class

            K Offline
            K Offline
            KarstenK
            wrote on last edited by
            #6

            Sorry: use a CString* is legal but you ar right using a CStringArray is best practice :->

            Greetings from Germany

            1 Reply Last reply
            0
            • R rajneshmalik

              hi all i want to allocate memory for two diamentional sring like CString mydata=new CString[10]; for "TWO DIAMENTION". I done CString mydata=new CString[10][10]; but compiler raise error how can i solve this problem; thank u in advance malik

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #7

              rajneshmalik wrote:

              i want to allocate memory for two diamentional sring

              try typedef std::vector<CString> vecCString; typedef std::vector<vecCString> vecTwoDimensionCString; typedef std::vector<vecTwoDimensionCString> vecThreeDimensionCString;

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              1 Reply Last reply
              0
              • R rajneshmalik

                hi all i want to allocate memory for two diamentional sring like CString mydata=new CString[10]; for "TWO DIAMENTION". I done CString mydata=new CString[10][10]; but compiler raise error how can i solve this problem; thank u in advance malik

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #8

                While you probably should use an array class as others have mentioned, you can create multi dimension arrays on the heap if you use the proper syntax: CString (*mydata)[10] = new CString[10][10]; ... delete[] mydata;

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                R 1 Reply Last reply
                0
                • M Mark Salsbery

                  While you probably should use an array class as others have mentioned, you can create multi dimension arrays on the heap if you use the proper syntax: CString (*mydata)[10] = new CString[10][10]; ... delete[] mydata;

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  R Offline
                  R Offline
                  rajneshmalik
                  wrote on last edited by
                  #9

                  hi first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u. i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u malik

                  M 1 Reply Last reply
                  0
                  • N Nishad S

                    rajneshmalik wrote:

                    I done CString mydata=new CString[10][10];

                    Two dimension array cannot be created like this. You have to do like

                        CString** pStr = new CString* [10];
                        for( int i = 0; i < 10; i++ )
                            pStr[i] = new CString[10];
                    

                    - NS -

                    R Offline
                    R Offline
                    rajneshmalik
                    wrote on last edited by
                    #10

                    hi first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u. i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u malik

                    N 1 Reply Last reply
                    0
                    • R rajneshmalik

                      hi first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u. i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u malik

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #11

                      rajneshmalik wrote:

                      i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,

                      In that case I don't see why you need a multi-dimension array. Directory listings are one-dimensional. A CStringArray is an excellent choice IMO. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      1 Reply Last reply
                      0
                      • R rajneshmalik

                        hi first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u. i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u malik

                        N Offline
                        N Offline
                        Nishad S
                        wrote on last edited by
                        #12

                        I CStringArray is enough for the purpose.

                        rajneshmalik wrote:

                        i am also getting memory leak problem

                        May you are not calling delete in the proper way.

                        - NS -

                        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