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. Store String in Array

Store String in Array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorial
27 Posts 8 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.
  • L LearnVC MFC

    No I am not misteke about CString. CString B; variable change at the runtime.Let Us take example.First time CString B="As"; Secon Time It's values changes now it's values is CString B="Cs". So i want to store these variable in Array. Plz help me. Forum every reply help US .Plz help me Thx's in Advance:rose:

    C Offline
    C Offline
    CPallini
    wrote on last edited by
    #18

    CString a[100];
    CString b;
    b = "As";
    a[0] = b;
    b = "Cs";
    a[1] = b;
    // ...and so on

    :) BTW probably a good C/C++ tutorial is needed.

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    L 1 Reply Last reply
    0
    • C Cedric Moonen

      How can you expect people to give you an answer when you can't even ask a proper question. You asked this: "I have two string CString A[100]and CString B.I want to store variable of B in A". The code I gave you does what you are asking for, so why do you still complain ? I asked you several time to rephrase your question properly, is it my fault if you can't express yourself ? If the code I gave you is not what you are looking for, then why do you continue asking exactly the same question over and over ?

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

      L Offline
      L Offline
      LearnVC MFC
      wrote on last edited by
      #19

      ok i accept it's my fault... Can i continue..IF yes the reply me.I will try to do more specific..

      M 1 Reply Last reply
      0
      • L LearnVC MFC

        ok i accept it's my fault... Can i continue..IF yes the reply me.I will try to do more specific..

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #20

        LearnVC++MFC wrote:

        I will try to do more specific..

        Go ahead.

        L 1 Reply Last reply
        0
        • M Michael Schubert

          LearnVC++MFC wrote:

          I will try to do more specific..

          Go ahead.

          L Offline
          L Offline
          LearnVC MFC
          wrote on last edited by
          #21

          Thanks I have told already about two String.CString a[100] and CString b; Every time b values is change at the run time.And i want to store every value of b at the run time. I have got some example

          CString a[10];
          CString b;
          a[0] = b;
          a[1] = b;

          But it is not proper working.Every time both a1[0] and a1[1] values is changed. But i want to store like that.. a[0]="assa",a[1]="iuf". So plz help me

          M C 2 Replies Last reply
          0
          • C CPallini

            CString a[100];
            CString b;
            b = "As";
            a[0] = b;
            b = "Cs";
            a[1] = b;
            // ...and so on

            :) BTW probably a good C/C++ tutorial is needed.

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            L Offline
            L Offline
            LearnVC MFC
            wrote on last edited by
            #22

            Thx's for reply.It's help me,but little more problem. Sir CString b values came into runtime and every time it's value is new.And this code Every time store new values in a[0]and a[1].But i need to store all new values and don't want to delete Old values.Plz help me

            C 1 Reply Last reply
            0
            • L LearnVC MFC

              Thanks I have told already about two String.CString a[100] and CString b; Every time b values is change at the run time.And i want to store every value of b at the run time. I have got some example

              CString a[10];
              CString b;
              a[0] = b;
              a[1] = b;

              But it is not proper working.Every time both a1[0] and a1[1] values is changed. But i want to store like that.. a[0]="assa",a[1]="iuf". So plz help me

              M Offline
              M Offline
              Michael Schubert
              wrote on last edited by
              #23

              First of all, CString a[100] is an array of type CString. In your example you assign the value of "b" to the first two elements of "a". So, your code does exactly what you described:

              LearnVC++MFC wrote:

              Every time both a1[0] and a1[1] values is changed

              If you want different values in a[0] and a[1] then you have to assign different values and not the same.

              1 Reply Last reply
              0
              • L LearnVC MFC

                Thanks I have told already about two String.CString a[100] and CString b; Every time b values is change at the run time.And i want to store every value of b at the run time. I have got some example

                CString a[10];
                CString b;
                a[0] = b;
                a[1] = b;

                But it is not proper working.Every time both a1[0] and a1[1] values is changed. But i want to store like that.. a[0]="assa",a[1]="iuf". So plz help me

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

                I really think you need to start by reading a good book on C++ because you don't know at all what you are doing. Do you know what an array is and how to use it ? It seems not. So, what you have to do is store each new string in a NEW position in the array, not overriding the previous values.

                CString a[10]; // This is an array of 10 strings, you can't store more than 10 strings in it

                CString b; // This is a single CString object
                b = "Test"; // You set a value in the b object
                a[0] = b; // You store this value in the FIRST position in the array.
                b = "Test2"; // You assign a new value to b.
                a[1] = b; // You store the new value of b at the SECOND position in the array, so you DON'T remove the value which is in a[0].
                // Continue until you have 10 strings in your array.

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

                1 Reply Last reply
                0
                • L LearnVC MFC

                  Thx's for reply.It's help me,but little more problem. Sir CString b values came into runtime and every time it's value is new.And this code Every time store new values in a[0]and a[1].But i need to store all new values and don't want to delete Old values.Plz help me

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #25

                  CString a[100];
                  CString b;
                  int i=0;
                  b = "As";
                  a[i] = b;
                  i = (i + 1) % 100;
                  b = "Cs";
                  a[i] = b;
                  i = (i + 1) % 100;
                  //..

                  :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  1 Reply Last reply
                  0
                  • L LearnVC MFC

                    Hi Forum I am new in this forum.I have a problem to store String variale in array. I have two string CString A[100]and CString B.I want to store variable of B in A.Like that A=B.Can any one give some example. Thxanks in Advance:rose:

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

                    Have you considered something like:

                    CStringArray A;
                    CString B;
                    B = "First value";
                    A.Add(B);
                    B = "Second value";
                    A.Add(B);
                    B = "Third value";
                    A.Add(B);
                    ...

                    "Love people and use things, not love things and use people." - Unknown

                    "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                    1 Reply Last reply
                    0
                    • C Cedric Moonen

                      :confused: I gave you code in my previous reply. Do you know what a CString class does ? You know that you can actually store a full string (e.g. "Hello") in a CString object ? So, when you have something like CString A[100], it actually means that you have an array of 100 CString objects (so, each one containing a separate string). If you still don't know what to do, then please reformat your question because I don't get it.

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

                      M Offline
                      M Offline
                      Mark Schumann
                      wrote on last edited by
                      #27

                      I understand the question. It's "please finish my homework assignment for me?"

                      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