Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 714659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:06:00+00:00 2026-05-14T05:06:00+00:00

I have a c++ source code that was written in linux/unix environment by some

  • 0

I have a c++ source code that was written in linux/unix environment by some other author.
It gives me errors when i compile it in windows vista environment. I am using Bloodshed Dev C++ v 4.9. please help.

#include <iostream.h>
#include <map>
#include <vector>
#include <string>
#include <string.h>
#include <strstream>
#include <unistd.h>
#include <stdlib.h>


using namespace std;

template <class T> class PrefixSpan {
private:
  vector < vector <T> >             transaction;
  vector < pair <T, unsigned int> > pattern;
  unsigned int minsup;
  unsigned int minpat;
  unsigned int maxpat;
  bool all;
  bool where;
  string delimiter;      
  bool verbose;
  ostream *os;

  void report (vector <pair <unsigned int, int> > &projected) 
  {
    if (minpat > pattern.size()) return;

    // print where & pattern
    if (where) { 
      *os << "<pattern>" << endl;

      // what:
      if (all) {
 *os << "<freq>" << pattern[pattern.size()-1].second << "</freq>" << endl;
 *os << "<what>";
 for (unsigned int i = 0; i < pattern.size(); i++) 
   *os << (i ? " " : "") << pattern[i].first;
      } else {
 *os << "<what>";
  for (unsigned int i = 0; i < pattern.size(); i++)
    *os << (i ? " " : "") << pattern[i].first 
        << delimiter << pattern[i].second;
      }

      *os << "</what>" << endl;

      // where
      *os << "<where>";
      for (unsigned int i = 0; i < projected.size(); i++) 
 *os << (i ? " " : "") << projected[i].first;
      *os << "</where>" << endl;

      *os << "</pattern>" << endl;

    } else {

      // print found pattern only
      if (all) {
  *os << pattern[pattern.size()-1].second;
  for (unsigned int i = 0; i < pattern.size(); i++)
    *os << " " << pattern[i].first;
      } else {
  for (unsigned int i = 0; i < pattern.size(); i++)
    *os << (i ? " " : "") << pattern[i].first
        << delimiter << pattern[i].second;
      }

      *os << endl;
    }
  }

  void project (vector <pair <unsigned int, int> > &projected)
  {
    if (all) report(projected);

    map <T, vector <pair <unsigned int, int> > > counter;

    for (unsigned int i = 0; i < projected.size(); i++) {
      int pos = projected[i].second;
      unsigned int id  = projected[i].first;
      unsigned int size = transaction[id].size();
      map <T, int> tmp;
      for (unsigned int j = pos + 1; j < size; j++) {
 T item = transaction[id][j];
 if (tmp.find (item) == tmp.end()) tmp[item] = j ;
      }

      for (map <T, int>::iterator k = tmp.begin(); k != tmp.end(); ++k) 
 counter[k->first].push_back (make_pair <unsigned int, int> (id, k->second));
    }

    for (map <T, vector <pair <unsigned int, int> > >::iterator l = counter.begin (); 
  l != counter.end (); ) {
      if (l->second.size() < minsup) {
 map <T, vector <pair <unsigned int, int> > >::iterator tmp = l;
 tmp = l;
 ++tmp;
 counter.erase (l);
 l = tmp;
      } else {
 ++l;
      }
    }

    if (! all && counter.size () == 0) {
      report (projected);
      return;
    }

    for (map <T, vector <pair <unsigned int, int> > >::iterator l = counter.begin (); 
  l != counter.end(); ++l) {
      if (pattern.size () < maxpat) {
  pattern.push_back (make_pair <T, unsigned int> (l->first, l->second.size()));
  project (l->second);
  pattern.erase (pattern.end());
      }
    }
  }

public:
  PrefixSpan (unsigned int _minsup = 1,
       unsigned int _minpat = 1,        
       unsigned int _maxpat = 0xffffffff,
       bool _all = false,
       bool _where = false,
       string _delimiter = "/",
       bool _verbose = false):
    minsup(_minsup), minpat (_minpat), maxpat (_maxpat), all(_all), 
    where(_where), delimiter (_delimiter),  verbose (_verbose) {};

  ~PrefixSpan () {};

  istream& read (istream &is) 
  {
    string line;
    vector <T> tmp;
    T item;
    while (getline (is, line)) {
       tmp.clear ();
       istrstream istrs ((char *)line.c_str());
       while (istrs >> item) tmp.push_back (item);
       transaction.push_back (tmp);
    }

    return is;
  }

  ostream& run (ostream &_os)
  {
    os = &_os;
    if (verbose) *os << transaction.size() << endl;
    vector <pair <unsigned int, int> > root;
    for (unsigned int i = 0; i < transaction.size(); i++) 
      root.push_back (make_pair (i, -1));
     project (root); 
    return *os;
  }

  void clear ()
  {
    transaction.clear ();
    pattern.clear ();
  }
};

int main (int argc, char **argv)
{
  extern char *optarg;
  unsigned int minsup = 1;
  unsigned int minpat = 1;
  unsigned int maxpat = 0xffffffff;
  bool all = false;
  bool where = false;
  string delimiter = "/";
  bool verbose = false;
  string type = "string"; 

  int opt;
  while ((opt = getopt(argc, argv, "awvt:M:m:L:d:")) != -1) {
    switch(opt) {
    case 'a':
      all = true;
      break;
    case 'w':
      where = true;
      break;
    case 'v':
      verbose = true;
      break;
    case 'm':
      minsup = atoi (optarg);
      break;
    case 'M':
      minpat = atoi (optarg);
      break;
    case 'L':
      maxpat = atoi (optarg);
      break;
    case 't':
      type = string (optarg); 
      break;
    case 'd':
      delimiter = string (optarg);
      break;
    default:
      cout << "Usage: " << argv[0] 
    << " [-m minsup] [-M minpat] [-L maxpat] [-a] [-w] [-v] [-t type] [-d delimiter] < data .." << endl;
      return -1;
    }
  }

  if (type == "int") { 
     PrefixSpan<unsigned int> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
     prefixspan.read (cin);
     prefixspan.run  (cout);
  }else if (type == "short") {
     PrefixSpan<unsigned short> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
     prefixspan.read (cin);
     prefixspan.run  (cout);
  } else if (type == "char") {
     PrefixSpan<unsigned char> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
     prefixspan.read (cin);
     prefixspan.run  (cout);
  } else if (type == "string") {
     PrefixSpan<string> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
     prefixspan.read (cin);
     prefixspan.run  (cout);
  } else { 
     cerr << "Unknown Item Type: " << type << " : choose from [string|int|short|char]" << endl;
     return -1;
  }

  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:06:00+00:00Added an answer on May 14, 2026 at 5:06 am

    Here we go, you’ve just got good compiler. mingw32-gcc compiler (which is DevCpp built-in compiler) just giving some error like this

    error: dependent-name ` T::int' is parsed as a non-type, but instantiation yields a type
    

    It does not take map <T, int>::iterator as a type because thats depends on Templates, you need to use typename keyword for dependent names

    So, use typename map <T, int>::iterator

    I have done test compiled here. there is source main.cpp file and compiled .exe file and a data file.

    And looks like you got those codes from here

    http://www.chasen.org/~taku/software/prefixspan/

    its GPL v2, you might need to add those license to your code too.

    Edit: Adding fixed codes for later reference

    /*
     PrefixSpan: An efficient algorithm for sequential pattern mining
    
     $Id: prefixspan.cpp,v 1.8 2002/04/03 13:35:23 taku-ku Exp $;
    
     Copyright (C) 2002 Taku Kudo   All rights reserved.
     This is free software with ABSOLUTELY NO WARRANTY.
    
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
    
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
     GNU General Public License for more details.
    
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     02111-1307, USA
    */
    
    #include <iostream>
    #include <map>
    #include <vector>
    #include <string>
    #include <string.h>
    #include <strstream>
    #include <unistd.h>
    #include <stdlib.h>
    
    using namespace std;
    
    template <class T> class PrefixSpan {
    private:
        vector < vector <T> >            transaction;
        vector < pair <T, unsigned int> > pattern;
        unsigned int minsup;
        unsigned int minpat;
        unsigned int maxpat;
        bool all;
        bool where;
        string delimiter;
        bool verbose;
        ostream *os;
    
    void report (vector <pair <unsigned int, int> > &projected){
        if (minpat > pattern.size()) return;
    
        // print where & pattern
        if (where) {
            *os << "<pattern>" << endl;
    
            // what:
            if (all) {
                *os << "<freq>" << pattern[pattern.size()-1].second << "</freq>" << endl;
                *os << "<what>";
                for (unsigned int i = 0; i < pattern.size(); i++)
                    *os << (i ? " " : "") << pattern[i].first;
                } else {
                    *os << "<what>";
                     for (unsigned int i = 0; i < pattern.size(); i++)
                        *os << (i ? " " : "") << pattern[i].first << delimiter << pattern[i].second;
                }
                *os << "</what>" << endl;
    
            // where
            *os << "<where>";
            for (unsigned int i = 0; i < projected.size(); i++)
                *os << (i ? " " : "") << projected[i].first;
            *os << "</where>" << endl;
            *os << "</pattern>" << endl;
        } else {
            // print found pattern only
            if (all) {
                 *os << pattern[pattern.size()-1].second;
                 for (unsigned int i = 0; i < pattern.size(); i++)
                    *os << " " << pattern[i].first;
                } else {
                     for (unsigned int i = 0; i < pattern.size(); i++)
                        *os << (i ? " " : "") << pattern[i].first << delimiter << pattern[i].second;
                }
    
            *os << endl;
        }
    }
    
    void project (vector <pair <unsigned int, int> > &projected){
        if (all) report(projected);
    
        map <T, vector <pair <unsigned int, int> > > counter;
    
        for (unsigned int i = 0; i < projected.size(); i++) {
            int pos = projected[i].second;
            unsigned int id = projected[i].first;
            unsigned int size = transaction[id].size();
            map <T, int> tmp;
            for (unsigned int j = pos + 1; j < size; j++) {
                T item = transaction[id][j];
                if (tmp.find (item) == tmp.end()) tmp[item] = j ;
            }
    
            for (typename map <T, int>::iterator k = tmp.begin(); k != tmp.end(); ++k)
                counter[k->first].push_back (make_pair <unsigned int, int> (id, k->second));
        }
    
        for (typename map <T, vector <pair <unsigned int, int> > >::iterator l = counter.begin ();
        l != counter.end (); ) {
            if (l->second.size() < minsup) {
                typename map <T, vector <pair <unsigned int, int> > >::iterator tmp = l;
                tmp = l;
                ++tmp;
                counter.erase (l);
                l = tmp;
            } else {
                ++l;
            }
        }
    
        if (! all && counter.size () == 0) {
            report (projected);
            return;
        }
    
        for (typename map <T, vector <pair <unsigned int, int> > >::iterator l = counter.begin ();
        l != counter.end(); ++l) {
            if (pattern.size () < maxpat) {
                 pattern.push_back (make_pair <T, unsigned int> (l->first, l->second.size()));
                 project (l->second);
                 pattern.erase (pattern.end());
            }
        }
    }
    
    public:
        PrefixSpan (unsigned int _minsup = 1,
                unsigned int _minpat = 1,
                unsigned int _maxpat = 0xffffffff,
                bool _all = false,
                bool _where = false,
                string _delimiter = "/",
                bool _verbose = false):
        minsup(_minsup), minpat (_minpat), maxpat (_maxpat), all(_all),
        where(_where), delimiter (_delimiter),  verbose (_verbose) {};
    
        ~PrefixSpan () {};
    
        istream& read (istream &is){
            string line;
            vector <T> tmp;
            T item;
            while (getline (is, line)) {
                tmp.clear ();
                istrstream istrs ((char *)line.c_str());
                while (istrs >> item) tmp.push_back (item);
                transaction.push_back (tmp);
            }
    
            return is;
        }
    
        ostream& run (ostream &_os){
            os = &_os;
            if (verbose) *os << transaction.size() << endl;
            vector <pair <unsigned int, int> > root;
            for (unsigned int i = 0; i < transaction.size(); i++)
                root.push_back (make_pair (i, -1));
             project (root);
            return *os;
        }
    
        void clear (){
            transaction.clear ();
            pattern.clear ();
        }
    };
    
    int main (int argc, char **argv){
        extern char *optarg;
        unsigned int minsup = 1;
        unsigned int minpat = 1;
        unsigned int maxpat = 0xffffffff;
        bool all = false;
        bool where = false;
        string delimiter = "/";
        bool verbose = false;
        string type = "string";
    
        int opt;
        while ((opt = getopt(argc, argv, "awvt:M:m:L:d:")) != -1){
            switch(opt) {
            case 'a':
                all = true;
                break;
            case 'w':
                where = true;
                break;
            case 'v':
                verbose = true;
                break;
            case 'm':
                minsup = atoi (optarg);
                break;
            case 'M':
                minpat = atoi (optarg);
                break;
            case 'L':
                maxpat = atoi (optarg);
                break;
            case 't':
                type = string (optarg);
                break;
            case 'd':
                delimiter = string (optarg);
                break;
            default:
                cout << "Usage: " << argv[0]
                << " [-m minsup] [-M minpat] [-L maxpat] [-a] [-w] [-v] [-t type] [-d delimiter] < data .." << endl;
                return -1;
            }
        }
    
        if (type == "int") {
             PrefixSpan<unsigned int> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
             prefixspan.read (cin);
             prefixspan.run (cout);
        }else if (type == "short") {
             PrefixSpan<unsigned short> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
             prefixspan.read (cin);
             prefixspan.run (cout);
        } else if (type == "char") {
             PrefixSpan<unsigned char> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
             prefixspan.read (cin);
             prefixspan.run (cout);
        } else if (type == "string") {
             PrefixSpan<string> prefixspan (minsup, minpat, maxpat, all, where, delimiter, verbose);
             prefixspan.read (cin);
             prefixspan.run (cout);
        } else {
            cerr << "Unknown Item Type: " << type << " : choose from [string|int|short|char]" << endl;
            return -1;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 359k
  • Answers 359k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Call ABAddressBookCopyArrayOfAllPeople() to get an array of all person records… May 14, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer Have you looked at Module.GetMethods? Returns the global methods defined… May 14, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer This issue can be caused by HTML generation being disabled.… May 14, 2026 at 2:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.