Eaco1412 2021-08-24 00:04 采纳率: 100%
浏览 6735
已结题

“In file included from”请问一下这个报错是什么意思

做pta上做1033 To Fill or Not to Fill这道题( PTA | 程序设计类实验辅助教学平台 千名教师建设,万道高质量题目,百万用户拼题的程序设计实验辅助教学平台 https://pintia.cn/problem-sets/994805342720868352/problems/994805458722734080 )的时候遇到的问题,代码功能应该还不完善,但现在最头疼的是看不到显示,报错也看不懂。请问一下下面的报错是什么问题?

In file included from /usr/include/c++/6/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = node*; _Iterator2 = node*]’:
/usr/include/c++/6/bits/stl_algo.h:1844:14:   required fromvoid std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1882:25:   required fromvoid std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1968:31:   required fromvoid std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:4707:18:   required fromvoid std::sort(_RAIter, _RAIter) [with _RAIter = node*]’
a.cpp:26:19:   required from here
/usr/include/c++/6/bits/predefined_ops.h:43:23: error: no match for ‘operator<’ (operand types are ‘node’ and ‘node’)
       { return *__it1 < *__it2; }
                ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/stl_iterator.h:888:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:888:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/predefined_ops.h:43:23: note:   ‘node’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
       { return *__it1 < *__it2; }
                ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/stl_iterator.h:895:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:895:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/predefined_ops.h:43:23: note:   ‘node’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
       { return *__it1 < *__it2; }
                ~~~~~~~^~~~~~~~
/usr/include/c++/6/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = node*; _Value = node]’:
/usr/include/c++/6/bits/stl_heap.h:129:48:   required fromvoid std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = node*; _Distance = long int; _Tp = node; _Compare = __gnu_cxx::__ops::_Iter_less_val]’
/usr/include/c++/6/bits/stl_heap.h:230:23:   required fromvoid std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = node*; _Distance = long int; _Tp = node; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_heap.h:335:22:   required fromvoid std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1669:23:   required fromvoid std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1930:25:   required fromvoid std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1945:27:   required fromvoid std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = node*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:1965:25:   required fromvoid std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/6/bits/stl_algo.h:4707:18:   required fromvoid std::sort(_RAIter, _RAIter) [with _RAIter = node*]’
a.cpp:26:19:   required from here
/usr/include/c++/6/bits/predefined_ops.h:56:22: error: no match for ‘operator<’ (operand types are ‘node’ and ‘node’)
       { return *__it < __val; }
                ~~~~~~^~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/stl_iterator.h:888:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:888:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/predefined_ops.h:56:22: note:   ‘node’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
       { return *__it < __val; }
                ~~~~~~^~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/stl_iterator.h:895:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:895:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/6/bits/char_traits.h:39,
                 from /usr/include/c++/6/ios:40,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/include/c++/6/complex:45,
                 from /usr/include/c++/6/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:52,
                 from a.cpp:3:
/usr/include/c++/6/bits/predefined_ops.h:56:22: note:   ‘node’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
       { return *__it < __val; }
                ~~~~~~^~~~~~~

我的代码如下

//水箱最多装v,距离目的地skm,一个单位的气体汽车可以走perskm远,一共n个站
//每个站气体价格是p[i],距离杭州x[i]
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
#define Equ(a,b) ((fabs((a)-(b)))<eps)
#define MoreEqu(a,b) (((a)-(b))>-eps)
#define More(a,b) ((fabs((a)-(b)))>eps)
struct node{
    double p,x;
}nod[501];
bool cmp(node a, node b)
{
    return a.x < b.x;//将加油站照位置升序排列
}
int main(){
    double v, s, pers, price,dis=0,oil=0,needoil;
    double temp,temx;
    int n;//n是一共多少个站
    //v是水箱容积,s是两站路程,pers是一单位油能走多远
    cin >> v >> s >> pers >> n;
    for (int i = 0; i <= n - 1; i++) {
        cin >> temp >> temx;
        getchar();
    }
    sort(nod,nod+n);
    if(nod[0].x!=0 || n<=0){
        printf("The maximum travel distance = 0.00");
        return 0;
    }
    nod[n].p=0;
    nod[n].x=s;
    double max=v*pers;//一次能走的最远距离
    int i=0;
    int j=1;
    int min =j;
    while(i<=n-1){
        if(j>n){
            printf("%.2f",price);
        }
        if(More((nod[j].x-nod[i].x),max)){
            printf("The maximum travel distance = %.2f",dis+max);
            return 0;
        }
        while(More(max,(nod[j].x-nod[i].x)) && j<=n){
             if(More(nod[min].p,nod[j].p)){
             min=j;
             j++;
            }
        }
        needoil=(nod[min].x-nod[i].x)/pers;
        dis=nod[min].x;
        i=min;
        j=i+1;
        min=j;
        if(More(nod[i].p,nod[min].p)){
            if(MoreEqu(needoil,oil)){
                price+=(needoil-oil)*nod[i].p;
            }
            
        }
        else{
            oil=oil+v-needoil;
            price+=v*nod[i].p;//油加满
        }
    }
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 关注

    错误的原因是代码第26行对结构体排序时没加排序方法cmp导致报错,加上后就可以运行了:

    sort(nod,nod+n,cmp);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月1日
  • 已采纳回答 8月24日
  • 创建了问题 8月24日

悬赏问题

  • ¥15 vue3的子组件在父页面调用不显示不生效问题
  • ¥15 怎么解决这种情况,求解
  • ¥15 cadence PEX
  • ¥15 phython创建了文件 显示在项目下面,但运行不了,运行时还是运行main文件,并且说main文件不允许并行运行
  • ¥20 C++哈希表的设计构造哈希表
  • ¥15 FutureWarning:不推荐使用空或全 NA 条目的 DataFrame 串联行为。怎么改呢?
  • ¥15 Chatgpt突然无法正常显示数学公式,如何解决?
  • ¥15 一个用华为模拟器做的实验。
  • ¥28 opencv Cuda C++编译
  • ¥15 插入sim卡4g模组反复断连