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 8883499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:49:37+00:00 2026-06-14T20:49:37+00:00

#include UserUserSim.h UserUserSim::UserUserSim(string &query_url): _query_url(query_url) { } void UserUserSim::calculate(){ ifstream infile(_query_url.c_str()); string line; while(infile){

  • 0
    #include "UserUserSim.h"
UserUserSim::UserUserSim(string &query_url):
    _query_url(query_url)
{

}

void UserUserSim::calculate(){
    ifstream infile(_query_url.c_str());
    string line;
    while(infile){
        int movie_id;
        int user_id;
        infile>>line;
        if (line[line.length()-1]==':'){
            movie_id=atoi(line.c_str());
            cout<<line<<endl;
        }
        else{
            user_id=atoi(line.c_str());
            if (_set.find(user_id)==_set.end())
                getTop(user_id);
            float score=getScore(user_id,movie_id);
            cout<<score<<endl;
        }
    }
}
float UserUserSim::getScore(int &user_id, int &movie_id){
    vector<USim>* p=_map[user_id];
    MovieList* ml=MovieDictionary::getInstance().getMovie(movie_id);
    ml->sortList();
    vector<UserScore>::iterator it;
    vector<USim>::iterator sim_it=p->begin();
    float score=0;
    float total_weight=0;
    for (it=ml->begin();it<ml->end();it++){
        while ((*it).user_id>(*sim_it).user_id){  // the user did not rate in ths movie
            sim_it++;
        }

        if ((*it).user_id==(*sim_it).user_id){
            score+=(*sim_it).score * (*it).rating;  // score of similarity * rating
            total_weight+=(*sim_it).score;
            sim_it++;   // move on to the next user
        }
    }
    score=score/total_weight;
    return score;
}
typedef pair<int, float> mapPair;
bool compareSim(mapPair p1, mapPair p2){
    return p1.second>p2.second;
}
bool compareID(mapPair p1, mapPair p2){
    return p1.first<p2.first;
}
void UserUserSim::getTop(int &user_id){
    vector<USim> list;
    vector<USim>* p=&list;
    _map.insert(pair<int,vector<USim>*>(user_id,p));
    _set.insert(user_id);

    UserList* ul=UserDictionary::getInstance().getUser(user_id);
    map<int,float> user_score_map;
    vector<MovieScore>::iterator it;
    vector<UserScore>::iterator it_movie; // the iterator for the movielist
    for (it=ul->begin();it<ul->end();it++){ // for each movie rating in the Vector
        int movie_id=(*it).movie_id;
        MovieList* ml=MovieDictionary::getInstance().getMovie(movie_id);
        for(it_movie=ml->begin();it_movie<ml->end();it_movie++){
            int user_id=(*it_movie).user_id;
            if (user_score_map.find(user_id)==user_score_map.end()){
                user_score_map.insert(pair<int,float>(user_id,0));
            }else{
                user_score_map[user_id]+=(*it).rating*(*it_movie).rating;// the vector's user rating x the rating of the movie,user
            }
        }
    }
    //vector< pair<int,float> > user_score_v;
    map<int,float>::iterator it_map;
    for (it_map=user_score_map.begin();it_map<user_score_map.end();it_map++){} //<=============where error happens
}

Notice that if I include the last line, I will get the error as follows:

g++ src/main.cpp src/CorpusExp.cpp src/MovieList.cpp src/MovieDictionary.cpp src/UserDictionary.cpp src/UserList.cpp src/UserUserSim.cpp -o recommend
src/UserUserSim.cpp: In member function ‘void UserUserSim::getTop(int&)’:
src/UserUserSim.cpp:81: error: no match for ‘operator<’ in ‘it_map < user_score_map. std::map<_Key, _Tp, _Compare, _Alloc>::end [with _Key = int, _Tp = float, _Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int, float> >]()’
make: *** [recommend] Error 1

Barely new to c++, I checked some reference, I thought it is OK to iterate the map, otherwise, how could I copy some of the elements (like top k) out of the map into a vector?

  • 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-06-14T20:49:38+00:00Added an answer on June 14, 2026 at 8:49 pm

    Relational comparisons, like operators < , > and so on, are only available for random access iterators.

    std::map iterators are bidirectional iterators, which is a much weaker spec than random access. You cannot use relational comparisons with bidirectional iterators. Map iterators are only comparable for equality. Use != comparison in your loop condition instead of <.

    Moreover, it is always a good idea to use equality comparisons whenever you can and relational comparisons only when you really have to, i.e. rely on a weaker set of requirements whenever possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <fstream> using namespace std; int main() { ifstream stream1(source.txt); string line
#include <stdio.h> int main(void){ char x [] = hello world.; printf(%s \n, &x[0]); return
#include <stdio.h> #include <string.h> int main(void) { char s[]= 9; printf(atoi = %d,atoi(s)); system(pause);
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> void main() { int x=5,y=6; printf(%d%d%d,x++,(y=x++),(x=y++)); } Can anyone please explain why
#include<iostream> #include<vector> std::vector<std::string> vector1; int main() { vector1.push_back(adadad); std::vector<std::string> vector2; vector2.push_back(adadd); if (vector1==vector2) {
#include <string> #include <iostream> using namespace std; int main(){ string s1=123; //Set up string

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.