小编Shi*_*war的帖子

iostream是头文件还是库

我刚刚开始学习 cpp,真正让我困惑的一件事是#include <iostream>or #include<vector>。有人说我们包含 iostream 库,有人说它#include用于包含头文件。但是iostream并且vector没有.h扩展名,那么它们怎么可能是头文件呢?另外,我们可以使用 包含一个库吗#include?这也让我思考 和 之间的iostream.h区别iostream。头文件是哪一个?哪一个是图书馆?如果我们只包含头文件那么为什么我们不写呢#include<vector.h>

标准cpp库包含什么?较小的库,例如容器库、实用程序库?

我尝试查看 cppreference 但无法理解

c++ iostream include header-files libraries

3
推荐指数
1
解决办法
1248
查看次数

std::lower_bound() 与 std::map::lower_bound()

算法库的lower_bound函数采用前向迭代器并返回下界。它对于向量工作得很好,但是当我将它用于地图时,我遇到了编译器错误。我的疑问是 std::map 支持双向迭代器,显然可以充当前向迭代器,那么为什么 std::lower_bound(map.begin(),map.end(),int value) 不起作用,但成员函数地图类,map.lower_bound(int value)适用于地图吗?这是一些示例代码供参考

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    
    vector<int>v = {1,1,1,2,3,4,2,3,2,5,6,12,12,9};
    map<int,int>mp;
    for(auto x:v)mp[x]++;
    
    for(int i=0;i<15;i++){
    
    auto it = mp.lower_bound(i); // this works
 //   auto it = lower_bound(mp.begin(),mp.end(),i) //this doesn't work
    if(it!=mp.end())
    cout<<i<<" lower bound is "<<it->first<<" and its frequency in vector is "<<it->second<<endl;
    
    
    }
    
    
    return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c++ dictionary stl lower-bound

0
推荐指数
1
解决办法
258
查看次数