Results 1 to 6 of 6

Thread: C/C++ string questions...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    25

    C/C++ string questions...

    hau can i declare a string variiable?

    i forgot it....

    and is this legal?

    string arr[1]={"xxxx","ddddddd"};

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: C/C++ string questions...

    Moved from the CodeBank.

  3. #3
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: C/C++ string questions...

    string s("hi"); string s= "hi";
    This would be:

    string arr[2]={"xxxx","ddddddd"};

    But I don't know if that works or not. If not, you'll have to assign then separately: arr[0]="blah"; arr[1]= "blah2";

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C/C++ string questions...

    It works, yes. It's just rarely done.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    25

    Re: C/C++ string questions...

    tnx a lot guys but it doesnt work...............



    but nvm i solved it
    it just need multiple arrays...
    coz every element in the array can store 1 char only so i need to set first the size of every array by creating multiple arrays
    arr[1][2]={"hi","xx"} <<<=========== now this code is valid

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C/C++ string questions...

    No, it's not. You're initializing more strings than the array has space for, and longer ones at that (if you count the characters between quotes, you always need to add one).

    The number between the brackets is the size of the array, not the highest accessible index, which is one less.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width