CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    1

    creating a string array to hold user inputed thing

    Help with the below code. It will not put anything in the arraY?!

    string locations[100];
    cin >> regionName;
    locations[0]=regionName;

    while( regionName != STOP)
    {
    int i = 1;
    cout<<end1 << "input" << regionName;
    locations[i] = regionName;
    cin >> regionName;
    int++;
    }

    Much longer program but i'm having trouble just getting stuff into the array to work with it. my teacher gave us a txt input so it is working and outputting all the regionNames. But when I check to see if anything is inside array above number 2 it doesn't work. And the last regionName enter is always in array part number 1. array spot 0 works... :\ ?

    any help would be great

  2. #2
    Join Date
    Jul 2009
    Posts
    37

    Re: creating a string array to hold user inputed thing

    Dear Rich child
    I guess being rich would definitely make one smart and it is true
    as I see you making this question

    1. you might need learn to about getline to eliminate priblems of space char within each regionname if any
    2. it is 'i' that is to increase not 'int' and should be put infront of whilelloop too
    3. from 2 you don't have to initialise location[0], hah
    4. learn also about vector, you can make a vector of strings instead of string arrays


    -Hoang Thach Quan
    Sig-na-tju-(r)

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: creating a string array to hold user inputed thing

    Dear Rich child
    Who ?

    learn also about vector, you can make a vector of strings instead of string arrays
    Please stop throwing with the phrase 'vector'... instead of that... answer the question. Vectors are nothing more than a simple list, and they are very OVERRATED.

    But when I check to see if anything is inside array above number 2 it doesn't work.
    You keep setting 'i' to 1.
    Code:
    int i = 1;
    Define 'i' outside the loop.
    Code:
    int i = 1;
    while( regionName != STOP)
    {
      ....
      i++;
    }

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: creating a string array to hold user inputed thing

    Quote Originally Posted by Skizmo View Post
    Vectors are nothing more than a simple list
    Well, std::list is nothing more than a simple list. std::vector is nothing more than an extremely convenient wrapper around a dynamic array. Big different in data structure land! (I know what you meant.)
    , and they are very OVERRATED.
    Perhaps, but they beat the heck out of doing the same operations manually. Of course, in some cases "the same operations" are not necessary.

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

Featured