|
-
February 12th, 2010, 06:07 PM
#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
-
February 12th, 2010, 06:31 PM
#2
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)
-
February 12th, 2010, 06:46 PM
#3
Re: creating a string array to hold user inputed thing
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.
Define 'i' outside the loop.
Code:
int i = 1;
while( regionName != STOP)
{
....
i++;
}
-
February 12th, 2010, 08:49 PM
#4
Re: creating a string array to hold user inputed thing
 Originally Posted by Skizmo
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|