我在尝试ifstream在一个块内使用 from 时遇到问题。(这是一个更大、更复杂的项目的一部分,所以我快速制作了一个只包含相关部分的小源文件。)
// foo.cpp, in its entirety:
#include <iostream>
#include <fstream>
#include <Block.h>
int main() {
    __block std::ifstream file("/tmp/bar") ;
    // ^ tried this with and without the __block
    void (^block)() = ^{
        file.rdbuf() ;
        file.close() ;
        file.open("/tmp/bar") ;
    } ;
    block() ;
}
如果我声明ifstreamwith __block,我会得到:
foo.cpp:6:24: error: call to implicitly-deleted copy constructor of
      'std::ifstream' (aka 'basic_ifstream<char>')
        __block std::ifstream file("/tmp/bar") ;
                              ^~~~
如果我在没有 的情况下声明它__block,我会得到:
foo.cpp:8:3: error: call to implicitly-deleted copy constructor of
      'const std::ifstream' (aka 'const basic_ifstream<char>')
                file.rdbuf() ;
                ^~~~
                // rdbuf() and (presumably) other const functions
foo.cpp:9:3: error: member function 'close' not viable: 'this' argument has
      type 'const std::ifstream' (aka 'const basic_ifstream<char>'), but
      function is not marked const
                file.close() ;
                ^~~~
                // open(), close(), and (presumably) other non-const functions
fstream在块内使用 s 的正确方法是什么?