String Array

This is a discussion on String Array within the C++ Programming forums, part of the General Programming Boards category; Hey, How do I make a string array like string blah[10]; blah[0]="blibity blah"; blah[1]="blibbering baww"; Thanks, Gr3g...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    27

    String Array

    Hey,

    How do I make a string array like

    string blah[10];


    blah[0]="blibity blah";
    blah[1]="blibbering baww";


    Thanks,

    Gr3g
    Chance favors the prepared mind.

    Vis. C++ 6.0

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Hi Gr3g,

    You need to copy the strings to your array:
    Code:
    char blah[2][100];  /* can hold 2 strings, each max 99 characters long */
    
    strcpy(blah[0], "blibity blah");
    strcpy(blah[1], "blibbering baww");
    or if you are using MFC:
    Code:
    CString blah[2];
    
    blah[0] = "blibity blah";
    blah[1] = "blibbering baww";

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    That is right ...

    Hi,
    I just want to add something ....

    Every string is an array of char, has the same number of char that the string has + "/0", which will allow it to have one more room for the " /0" { "/0 means end of hte string "}

    Now you can do what monster told you to do, or you can use dinamic array,

    As in the same above,,,!

    C++
    The best

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    See ... I tried it ...

    it won't give you any kind of misstake...
    you better be carful next time...

    I hope that helped you ....
    C++
    The best

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    27

    Talking :)

    Yes thank you, Im going to write my program now, when (hehe or if) i finish ill post the code...


    Gr3g
    Chance favors the prepared mind.

    Vis. C++ 6.0

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Or...
    Code:
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        string blah[2] = { "blibity blah", "blibbering baww" };
    
        cout << blah[0] << ' ' << blah[1] << endl;
    
        return 0;
    }
    Prints out: blibity blah blibbering baww
    I used to be an adventurer like you... then I took an arrow to the knee.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to array of string and Array of Pointer to String
    By vb.bajpai in forum C Programming
    Replies: 2
    Last Post: 06-15-2007, 06:04 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21