11-30-2012, 01:32 PM
|
#4
|
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: C++ fstream and arrays
You can set up an if/else statement for each block of text you read in. This will change depending on how you're inputting (strings, chars, ints), but it would look something like this:
Code:
for(blah blah blah)
{
if(input == ' ' || input == '[' || input == ',' || input == ']')
continue;
else
(insert into array or however you're storing the inputs)
}
The continue command if you didn't know restarts the loop basically. So say you're at the 5th iteration and the input is a space, it'll start the loop at the beginning from the 6th iteration.
EDIT: You can just read in everything as strings and input them like username [ # # # # # ][ # ][ # ] and you should be fine. Just make sure you use " marks if you're ever checking things (ie, guess = "22").
EDIT 2: Doing ^, you can also test for usernames pretty easily. Just test if(input.length() > 2). If the test succeeds, that means it can't be a 2 digit number and must be a username allowing you to place it in the correct array.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Last edited by Kibblre; 11-30-2012 at 01:41 PM..
|
|
|