![]() |
1
11
关于
|
![]() |
2
26
您需要使用可复制/refrencable对象,其工作原理如下: #include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> void print_i(int t, std::string separator) { std::cout << t << separator; } int main() { std::vector<int> elements; std::string delim = "\n"; for_each(elements.begin(), elements.end(), std::bind2nd(std::ptr_fun(&print_i),delim)); return 0; } 通常,您只需执行以下操作即可获得相同的效果: #include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { std::vector<int> elements; std::copy(elements.begin(), elements.end(), std::ostream_iterator<int>(std::cout,"\n")); return 0; } 另外,假设您可以访问正在使用的STL中的tr1,那么最好用std::bind修改/替换bind1st和bind2nd的任何用法。 |
![]() |
3
3
您需要执行以下步骤:
我在一个例子中做了所有这些。您可以通过以下链接阅读文章并下载完整的代码: bind and find |
![]() |
4
1
这些函数从C++ 11中被剔除,在C++ 17中被删除。正如上面一条评论中提到的,现在更好的解决方案是使用
变成:
|
|
Julia · 矢量中相加为总和S的值的数量 2 年前 |
![]() |
C_Rod · 在模板方法中确定STL容器中项目的数据类型 3 年前 |
![]() |
quantumwell · 将空向量放入std::map() 7 年前 |
![]() |
OutOfBound · 对未初始化内存使用算法的优点 7 年前 |
![]() |
DarthRubik · 在使用列表删除之后,迭代器如何不无效 7 年前 |