Copy data from fstream to stringstream with no buffer?

后端 未结 5 1357
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 19:02

Is there anyway I can transfer data from an fstream (a file) to a stringstream (a stream in the memory)?

Currently, I\'m using a buffer, but th

5条回答
  •  逝去的感伤
    2021-02-01 19:11

    // need to include  and , and of course  and 
    ifstream fin("input.txt");
    ostringstream sout;
    copy(istreambuf_iterator(fin),
         istreambuf_iterator(),
         ostreambuf_iterator(sout));
    

提交回复
热议问题