相关疑难解决方法(0)

使用boost :: iostreams :: tee_device?

有人能帮我吗?

我想尝试做以下事情:

#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
#include <sstream>  
#include <cassert>  

namespace io = boost::iostreams;
typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee;
std::stringstream ss1, ss2;
Tee my_split(ss1, ss2); // redirects to both streams
my_split << "Testing";
assert(ss1.str() == "Testing" && ss1.str() == ss2.str());
Run Code Online (Sandbox Code Playgroud)

但它不会在VC9中编译:

c:\lib\boost_current_version\boost\iostreams\stream.hpp(131) : error C2665: 'boost::iostreams::tee_device<Sink1,Sink2>::tee_device' : none of the 2 overloads could convert all the argument types
Run Code Online (Sandbox Code Playgroud)

有没有人得到这个工作?我知道我可以自己上课去做,但我想知道我做错了什么.

谢谢

c++ iostream stream boost-iostreams

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

将std :: cout的副本重定向到该文件

我需要将std :: cout 的副本重定向到该文件.即我需要在控制台和文件中看到输出.如果我用这个:

// redirecting cout's output
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  streambuf *psbuf, *backup;
  ofstream filestr;
  filestr.open ("c:\\temp\\test.txt");

  backup = cout.rdbuf();     // back up cout's streambuf

  psbuf = filestr.rdbuf();   // get file's streambuf
  cout.rdbuf(psbuf);         // assign streambuf to cout

  cout << "This is written to the file";

  cout.rdbuf(backup);        // restore cout's original streambuf

  filestr.close();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后我将字符串写入文件,但我在控制台中看不到任何内容.我该怎么做?

c++

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

镜像控制台输出到c ++文件

在C++中,是否有一种智能方法可以将stdout的输出镜像到控制台和文件?我希望有一种方法可以像这个问题那样做.

编辑:能够只用标准库(即:没有提升)来做这件事会很好.

c++ io stdout

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

使用输出重定向打印到命令行

我在C++应用程序中使用printf()来从Linux命令行运行它时打印一些信息.现在,我正在使用输出重定向(./main> output.txt)将结果保存到文件中.我想知道是否可以同时使用两者:在程序运行时在命令行中查看结果,并进行输出重定向; 没有在C++中通过文件I/O明确地执行它.

c++ unix

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

标签 统计

c++ ×4

boost-iostreams ×1

io ×1

iostream ×1

stdout ×1

stream ×1

unix ×1