I believe 2 posts recently have covered this briefly, but I haven't found anything definitive. (1) I need to take a file and output data that includes both duplicates and (2) non-duplicates, then (3) outputs the results in a nice, clean sequence. I am totally confused as to how to look for duplicates, which then complicates step 3 as well. void removeduplicates () is the function I do not know how to even begin on.
2) An array creates N objects, numbered 0 through N-1. Thus: [code]line[100][/code] is invalid.
That said, why do you need 100 strings anyway? Just use one.
string line;
3) Capitalization matters. "Line" != "line".
4) Don't loop on EOF.
1 2 3 4
while (getline(myfile,line))
{
cout << line << "\n";
}
5) To remove duplicates, use a std::set. Here's an example with integers:
6) When you read your file, store the (names?) you get in a std::vector (or, if you must, an array). When you are ready to remove duplicates, you can copy the elements to a set<string> or you can #include <algorithm> and use std::sort() and std::unique():