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 array

string array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorialquestion
13 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.
  • J Offline
    J Offline
    J5121982
    wrote on last edited by
    #1

    how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ

    D R K H 4 Replies Last reply
    0
    • J J5121982

      how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      J5121982 wrote:

      CString strarr[]={"JAYARAJ","bala"}

      What are you trying to do here? strarr is not an array like you might think. If you need an array of CString objects, use CStringArray. Otherwise, you'll need something like:

      char *strarr[] = {"JAYARAJ", "bala"};


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      1 Reply Last reply
      0
      • J J5121982

        how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        Your function returns _one_ CString, not an array.

        CStringArray myclass::getStr()
        {
        CStringArray csa;
        csa.Add("str1");
        csa.Add("str2");
        return csa;
        }

        ~RaGE(); -- modified at 8:55 Thursday 30th March, 2006 : Sorry David, you posted while I was writing.

        J 1 Reply Last reply
        0
        • J J5121982

          how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ

          K Offline
          K Offline
          khan
          wrote on last edited by
          #4

          You could use a vector of CStrings:

          vector<CString> Doit()
          {
          CString s;
          vector<CString> a;
          s = "as";
          a.push_back(s);
          s = "ass";//this one is for my boss.
          a.push_back(s);
          return a;
          }

          Now to use it:

          CString s;
          vector<CString> a;
          a = Doit();

          this is this.

          J 1 Reply Last reply
          0
          • K khan

            You could use a vector of CStrings:

            vector<CString> Doit()
            {
            CString s;
            vector<CString> a;
            s = "as";
            a.push_back(s);
            s = "ass";//this one is for my boss.
            a.push_back(s);
            return a;
            }

            Now to use it:

            CString s;
            vector<CString> a;
            a = Doit();

            this is this.

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #5

            khan++ wrote:

            s = "ass";//this one is for my boss.

            :laugh: Watch out! He might be reading Code Project... :-D

            K 1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              khan++ wrote:

              s = "ass";//this one is for my boss.

              :laugh: Watch out! He might be reading Code Project... :-D

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

              :-D Actually I have never seen him. And as far as I can tell, I am still anonymous. this is this.

              T 1 Reply Last reply
              0
              • K khan

                :-D Actually I have never seen him. And as far as I can tell, I am still anonymous. this is this.

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

                Birthday : Friday 16th December, 1977
                Location : Pakistan

                unless those informations are false, you're not really anonymous... ;)

                K 1 Reply Last reply
                0
                • T toxcct

                  Birthday : Friday 16th December, 1977
                  Location : Pakistan

                  unless those informations are false, you're not really anonymous... ;)

                  K Offline
                  K Offline
                  khan
                  wrote on last edited by
                  #8

                  Heyyyyyy! It was supposed to be confidential.:) this is this.

                  T 1 Reply Last reply
                  0
                  • K khan

                    Heyyyyyy! It was supposed to be confidential.:) this is this.

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    sorry, i did not see any red bold stamp saying...

                    [CONFIDENTIAL] [DO NOT OPEN]

                    ...so, i read it... :rolleyes:

                    K 1 Reply Last reply
                    0
                    • T toxcct

                      sorry, i did not see any red bold stamp saying...

                      [CONFIDENTIAL] [DO NOT OPEN]

                      ...so, i read it... :rolleyes:

                      K Offline
                      K Offline
                      khan
                      wrote on last edited by
                      #10

                      Well, it was implicit... Ok, very funny. :laugh: Gotta go now. this is this.

                      1 Reply Last reply
                      0
                      • R Rage

                        Your function returns _one_ CString, not an array.

                        CStringArray myclass::getStr()
                        {
                        CStringArray csa;
                        csa.Add("str1");
                        csa.Add("str2");
                        return csa;
                        }

                        ~RaGE(); -- modified at 8:55 Thursday 30th March, 2006 : Sorry David, you posted while I was writing.

                        J Offline
                        J Offline
                        J5121982
                        wrote on last edited by
                        #11

                        i got this error what to do? error C2558: class 'CStringArray' : no copy constructor available JAYARAJ

                        R 1 Reply Last reply
                        0
                        • J J5121982

                          i got this error what to do? error C2558: class 'CStringArray' : no copy constructor available JAYARAJ

                          R Offline
                          R Offline
                          Rage
                          wrote on last edited by
                          #12

                          You cannot use the = operator on a CStringArray, you'll have to use the Copy function. ~RaGE();

                          1 Reply Last reply
                          0
                          • J J5121982

                            how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ

                            H Offline
                            H Offline
                            HvalaMne
                            wrote on last edited by
                            #13

                            J5121982 wrote:

                            CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...?

                            Of course u have type conflict. It look like you wrote int myclass::getInt() { int arr[]={1,1} return arr; } May be this helps:

                            CString[] myclass::getStr()
                            {
                            CString strarr[]={"JAYARAJ","bala"}
                            return strarr;
                            }

                            It should work, if no then try this

                            CString *myclass::getStr()
                            {
                            CString strarr[]={"JAYARAJ","bala"}
                            return (CString *)strarr;
                            }

                            BTW strarr seems to have local scope. So what you want to return is unclear. If I understand what you try to do, it better to declare it in class itself:

                            class myclass{
                            ...
                            public: /*private if you want*/
                            CString strarr[]={"JAYARAJ","bala"}

                            ....

                            }

                            or specify static class storage

                            CString[] myclass::getStr()
                            {
                            static CString strarr[]={"JAYARAJ","bala"}
                            return strarr;
                            }

                            -- modified at 2:42 Friday 31st March, 2006 -- modified at 2:48 Friday 31st March, 2006

                            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