pair vector

Not sure why I cant get my bool function to compile. This is my first time trying a pair vector, so It's probably stupid but can anyone see why my code is giving me these errors?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<string>
#include<cstring>
#include<cctype>
#include<vector>
#include<cmath>
using namespace std;

void print_vector( vector <string> v);
void fill_vector( vector < pair<int, string> > &v);
bool placment( pair<int, string> p1, pair<int, string> p2);
void count_vector( vector < pair<int, string> > &v);


int main()

{


        vector < pair<int, string> > v;

        fill_vector(v);

        cout << endl;

        count_vector(v);


        return 0;
}//main


void fill_vector( vector < pair<int, string> > &v){

        int x;
        string name;

        ifstream inf;
        string input = "input_file.txt";
        inf.open (input.c_str());

        while (inf >> x >> name){

                v.push_back(pair<int, string> (x, name));

        }
        sort(v.begin(), v.end(), placment);
        inf.close();
}

bool placment( pair<int, string> p1, pair<int, string> p2){

        return (p1.first < p2.second);
}

void count_vector( vector < pair<int, string> > &v){

        int y = 1;
        string s = v[0].second;

        ofstream out;
        out.open ("names.txt");

        for(int i  = 0; i < v.size(); i ++){
                if (v[i].second == s){
                        y++;
                }
                else{
                        out << setw(15) << s << setw(5) << y << endl;
                        s = v[i].second;
                        y = 1;
                }
        }
        out << setw(15) << s << setw(5) << y << endl;

}

void print_vector( vector < pair<int, string> > &v){

        for(int i = 0; i < v.size(); i ++){
                cout << v[i].second << endl;
        }
}



project3.cpp: In function 'bool placment(std::pair<int, std::basic_string<char> >, std::pair<int, std::basic_string<char> >)':
project3.cpp:56:31: error: no match for 'operator<' in 'p1.std::pair<int, std::basic_string<char> >::first < p2.std::pair<int, std::basic_string<char> >::second'
project3.cpp:56:31: note: candidates are:
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_algobase.h:65:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/char_traits.h:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_pair.h:218:5: note: template<class _T1, class _T2> bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_pair.h:218:5: note: template argument deduction/substitution failed:
project3.cpp:56:31: note: mismatched types 'const std::pair<_T1, _T2>' and 'int'
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_algobase.h:68:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/char_traits.h:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_iterator.h:299:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_iterator.h:299:5: note: template argument deduction/substitution failed:
project3.cpp:56:31: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_algobase.h:68:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/char_traits.h:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:41,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_iterator.h:349:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_iterator.h:349:5: note: template argument deduction/substitution failed:
project3.cpp:56:31: note: mismatched types 'const std::reverse_iterator<_IteratorL>' and 'int'
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/string:54:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/locale_classes.h:42,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/ios_base.h:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/basic_string.h:2566:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/basic_string.h:2566:5: note: template argument deduction/substitution failed:
project3.cpp:56:31: note: mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'int'
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/string:54:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/locale_classes.h:42,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/ios_base.h:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/basic_string.h:2578:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/basic_string.h:2578:5: note: template argument deduction/substitution failed:
project3.cpp:56:31: note: mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'int'
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/string:54:0,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/locale_classes.h:42,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/ios_base.h:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ios:43,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/ostream:40,
from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/iostream:40,
from project3.cpp:1:

1
2
3
bool placment( pair<int, string> p1, pair<int, string> p2){
        return (p1.first < p2.second);
}
¿how do you compare a number and a string?
42 < "answer"
Thank you. p1.first< p2.first
Topic archived. No new replies allowed.