【问题标题】:Copying (not redirecting) Visual C++ console output to text file while still viewing the output in console window将 Visual C++ 控制台输出复制(不重定向)到文本文件,同时仍在控制台窗口中查看输出
【发布时间】:2015-10-16 17:09:04
【问题描述】:

已就这个问题提出了各种各样的问题并得到了回答 https://stackoverflow.com/a/21709463/3906864

我按照上面链接的答案做了以下操作

">log.txt"

该参数已添加到此处

这允许控制台输出从控制台重定向到文件,并且控制台窗口保持空白,其中不显示任何内容。

但我找不到在控制台中查看输出同时仍将副本保存到 txt 文件的方法。 有什么想法吗?

【问题讨论】:

  • 一种方法是编写一个替换cout(或cerr)的“tee”。您可以通过编写自己的 ostreamrdbuf 来做到这一点。提示here

标签: c++ visual-studio visual-c++


【解决方案1】:

您需要tee 的版本。 Powershell有Tee-Object(https://technet.microsoft.com/en-us/library/hh849937.aspx)

链接示例

get-process | tee-object -filepath C:\Test1\testfile2.txt

以上将输出到终端和文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多