strange error... someone help please///

This is a discussion on strange error... someone help please/// within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by laserlight
    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.
    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'/

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> 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.

  4. #19
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by Daved
    >> 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?

    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...

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    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
    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.
    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;
    }
    I suggest that you use the references:
    C/C++ Reference
    SGI's STL Programmer's Guide
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    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

  7. #22
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by Daved
    Create an object of type StringSet and give it the word and the file information (presumably it stores strings inside somehow). Then call push_back on the vector with that object so that you are adding a StringSet to the vector.
    correct me if i am wrong please...

    Code:
    class InvertedIndex 
    {
    //insert data member here
      vector<StringSet> storage;
    and

    [code]

  8. #23
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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.

  9. #24
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by Daved
    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.

    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.

  10. #25
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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.

  11. #26
    Registered User
    Join Date
    Sep 2006
    Posts
    9
    any idea of how to do that?

  12. #27
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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.

  13. #28
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by Daved
    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..
    is this what you mean by including this code in the header file on private section??

    Code:
      struct inputType
      {
          string word;
          StringSet file;
      } InvertedIndex;

  14. #29
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  4. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 07:40 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21