小编and*_*llr的帖子

在不推进[Pythonic方法]的情况下从文件中读取一行

什么是pythonic方法从文件中读取一行而不是前进到文件中的位置?

例如,如果您有一个文件

cat1
cat2
cat3
Run Code Online (Sandbox Code Playgroud)

而你file.readline()会得到你cat1\n.接下来file.readline()会回来cat2\n.

有一些功能,例如file.some_function_here_nextline()cat1\n您可以稍后做file.readline(),并取回cat1\n

python

21
推荐指数
2
解决办法
1万
查看次数

在C++ 11之前有类似于std :: function的东西吗?

std::function<>当C++ 11不可用时,应该使用什么构造作为代理?
替代应该基本上允许从另一个类访问一个类的私有成员函数,如下例所示(不使用std :: function的其他功能).类Foo是固定的,不能改变太多,我只能访问类Bar.

class Foo {
  friend class Bar; // added by me, rest of the class is fixed
  private:

  void doStuffFooA(int i);
  void doStuffFooB(int i);
};

class Bar {
  public:

  Bar( Foo foo, std::function< void (const Foo&, int) > func ) {
    myFoo = foo;
    myFooFunc = func;
  };

  private:

  doStuffBar( const &Foo foo ) {
    myFooFunc( foo, 3 );
  }

  Foo myFoo;
  std::function< void (const Foo&, int) > myFooFunc;
}

int main() {

  Foo foo(...); …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 std-function

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

标签 统计

c++ ×1

c++11 ×1

python ×1

std-function ×1