Apr 8, 2013 at 9:46pm UTC
so i want a program that reads from a file with the format: name, gender.
but the name can either be 1,2 or 3 words.
so i was thinking to calculate the number of words and then assign to arrays
am i on the right track?
thanks for your help in advance
Last edited on Apr 14, 2013 at 7:24am UTC
Apr 8, 2013 at 10:20pm UTC
If the format actually is "name, gender" and not "name gender", then you can just use getline(blah, blah, ',');
Apr 8, 2013 at 10:33pm UTC
huh... i wish I had known that before...
so it will either get a line, or 'get' until the 3rd char arg is reached?
that is awsome and I'm trying that out right now, lol
Also, another thing:
couldn't you just out it with a space in between, and then getline(in, line, ' ' );
?
Last edited on Apr 8, 2013 at 10:34pm UTC
Apr 8, 2013 at 10:36pm UTC
Well if the name has spaces in it that won't work, and in any case it has the same behavior as the >> operator, which is that it reads until it gets a space.
Apr 8, 2013 at 10:42pm UTC
Heyy no it doesnt have commas seperating it ... just space...
e.g. Joe John M
or
Eliza Beth Lo F
Last edited on Apr 8, 2013 at 10:42pm UTC
Apr 8, 2013 at 10:53pm UTC
Well, you can check how many words there are and you know that the last one is the gender. I think this is what you wanted to do but it certainly isn't what you programmed.
Last edited on Apr 8, 2013 at 10:54pm UTC