小编zoo*_*zoo的帖子

奇怪的cout行为

我在Ubuntu上编译了一个为Windows开发(并在其上工作)的程序.在Ubuntu上,我看到这段代码:

string s = values_[9];
cout << s << endl;
cout << s << "x\n";
Run Code Online (Sandbox Code Playgroud)

产生这个输出:

high
xigh
Run Code Online (Sandbox Code Playgroud)

第二行的预期输出是"highx".我知道values_ [9]的值最初是从文件中读取的(在Windows上编写).打印其他字符串似乎正常工作.

这里发生了什么?

c++ cout

5
推荐指数
1
解决办法
184
查看次数

Haskell随机数生成

在Haskell中处理随机数生成的最佳方法是什么(或者什么是权衡)?

我还没有真正看到权威的答案.

考虑:最小化对其他纯功能的影响,如何/何时播种,性能,线程安全

random monads haskell

5
推荐指数
1
解决办法
897
查看次数

在C++中将成员函数指针"强制转换"为函数指针的最简单方法是什么?

我想为STL算法的"comp"参数提供成员函数,如lower_bound(...,Compare comp).comp()函数访问非静态成员字段,因此它本身必须是非静态成员,但非静态成员函数指针的类型不同于普通函数指针的类型.

解决这个问题的最佳方法是什么?

c++ pointers function member

4
推荐指数
2
解决办法
567
查看次数

使用STL make_heap实现Dijkstra算法

至少有几个答案建议使用STL堆函数在Dijkstra算法中实现优先级队列:

Dijkstra算法实现的性能

实现Dijkstra算法

考虑到STL不包含用于更新密钥的堆函数,在堆中重新排序顶点(第19行)的最佳方法是什么?

c++ implementation stl dijkstra

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

bind()用于使用成员函数作为STL比较函数

有人能告诉我为什么以下不会编译?

#include "a.h"
#include <list>
#include <algorithm>
#include <tr1/functional>

using namespace std;

class B {
  public:
    B() {
      list< A* > aList;
      A* a = new A();
      lower_bound( aList.begin(), aList.end(), a, tr1::bind( &B::aComp, tr1::placeholders::_1, tr1::placeholders::_2 ) );
    }
  private:
    bool aComp( A* a1, A* a2 );
};
Run Code Online (Sandbox Code Playgroud)

编译输出:

In file included from c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1/functional:56, 
from ..\bindTest\/b.h:4, 
from ..\bindTest\b.cpp:1: 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional: In member function 'typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args, std::tr1::is_bind_expression::value, (std::tr1::is_placeholder::value > 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::__call(const std::tr1::tuple<_UElements ...>&, std::tr1::_Index_tuple<_Indexes ...>) [with _Args = …
Run Code Online (Sandbox Code Playgroud)

c++ comparison stl bind

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

标签 统计

c++ ×4

stl ×2

bind ×1

comparison ×1

cout ×1

dijkstra ×1

function ×1

haskell ×1

implementation ×1

member ×1

monads ×1

pointers ×1

random ×1