hmm... have you considered using std::set<std::string> or std::multiset<std::string>? You should be able to take advantage of the generic algorithms std::set_intersection and std::set_union.
hmm... have you considered using std::set<std::string> or std::multiset<std::string>? You should be able to take advantage of the generic algorithms std::set_intersection and std::set_union.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
yeah i am planning to use set.. cause it is built in library which is my advantage.. but i dont know how to start.. can you guide me please'/Originally Posted by laserlight
>> this is my stringset class
I don't know what you are trying to do in total. The solution to your specific error is what I posted before. As I said, the StringSet has a way to insert strings, so create a StringSet object, add the strings, and push_back that StringSet object.
Whether this is actually the right approach for what you are doing or not, I don't know. It doesn't seem right. If you want help with this, maybe you can explain in English (not code) what InvertedIndex should be doing, what list is supposed to do, why you chose to make it vector<StringSet>, and any other details about this.
To get started with std::set, just look at your favorite reference for the types of functions available.
can you please make an example of your explanation?Originally Posted by Daved
for wat you mean by create a stringset object.. is it like this vector <StringSet> list; ??
wat you mean by add string? and i cannot push_back to the list being declared .. i tried it before..
thank you very much .. daved...
After having spent over a month working with Java, I decided to spend a little time working out a C++ example for you. Still, as Daved noted, we do not know what exactly you are trying to do. All this example serves is to show that you probably do not need to implement a StringSet class.yeah i am planning to use set.. cause it is built in library which is my advantage.. but i dont know how to start.. can you guide me please
I suggest that you use the references:Code:#include <set> #include <string> #include <algorithm> #include <iostream> typedef std::set<std::string> StringSet; void print(StringSet::iterator begin, StringSet::iterator end) { std::cout << "{"; while (begin != end) { std::cout << *begin << ","; ++begin; } std::cout << "}\n"; } int main() { StringSet set1; set1.insert("one"); set1.insert("two"); set1.insert("three"); set1.insert("one"); std::cout << "Set1: "; print(set1.begin(), set1.end()); // see if "two" is in the set if (set1.find("two") != set1.end()) { std::cout << "\"two\" is in set1.\n"; } else { std::cout << "\"two\" is not in set1.\n"; } StringSet set2; set2.insert("two"); set2.insert("three"); set2.insert("five"); std::cout << "Set2: "; print(set2.begin(), set2.end()); StringSet intersection_set; // find the intersection of set1 and set2 std::set_intersection( set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection_set, intersection_set.end())); std::cout << "Intersection: "; print(intersection_set.begin(), intersection_set.end()); StringSet union_set; // find the union of set1 and set2 std::set_union( set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(union_set, union_set.end())); std::cout << "Union: "; print(union_set.begin(), union_set.end()); return 0; }
C/C++ Reference
SGI's STL Programmer's Guide
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thank you thank you ....
ok i explain it in english.. i am going to build a small search engine for text files...the search engine will create an index from a set of files and will then allow you to pose queries. similar like google and yahoo searches....
it is structured into two parts, they are StringSet class and Invertedindex class
correct me if i am wrong please...Originally Posted by Daved
andCode:class InvertedIndex { //insert data member here vector<StringSet> storage;
[code]
How would you create an instance of int? How would you create an object of type string? How would you create a variable whose type is StringSet?
The code you posted created a member variable called storage in the class InvertedIndex with the type vector<StringSet>. That's not quite the same.
Your english explanation is a good start. Now try to explain, still in English, what you want the InvertedIndex class to do and what you want the StringSet class to do. The more paragraphs the more likely it is that we will be closer to understanding.
Originally Posted by Daved
i am sorry... ok here is it..
i am doing the FREE TEXT SEARCH
it is to build an inverted index of the words in the documents. this index consists of a list of words and for each word a set of the files that the word occurs in.
in my StringSet class, it stores a set of strings and provides some operations that will be useful in the implementation of the search engine. StringSet are used to store the list of files containing a word and as the result of a query.
AND the InvertedIndex class will make use of StringSet to store the set of files associated with each word. HINT, you will probably want to store a vector of something which might contain both word and a StringSet containing the files for tat word.
Ok, that helps.
So, in your InvertedIndex class, you want to store a vector of something which might contain both word and a StringSet containing the files for that word. That suggests to me that vector<StringSet> isn't quite right, since you need to hold the word and the StringSet, but that only holds a StringSet.
I think you need to come up with a new class or struct or "something" that holds a word and a StringSet of the files it is in. That shouldn't be too difficult to do. Once you get that then you can move on to storing a vector of that "something" in your InvertedIndex class.
any idea of how to do that?
I think you need to come up with a new class or struct or "something" that holds a word and a StringSet of the files it is in.
If you haven't learned how to make a class or struct, then this assignment is probably over your head anyway.
hi daved..Originally Posted by Daved
is this what you mean by including this code in the header file on private section??
Code:struct inputType { string word; StringSet file; } InvertedIndex;
Close, that creates a struct named inputType. The InvertedIndex part is not needed, since it creates a variable of type inputType with the name InvertedIndex. That's not what you want. You want a variable of type inputType to be a member of the InvertedIndex class.