VS2017将信息输出到text文件

使用fopen fprintf fclose来处理

FILE *input;
input= fopen("###.txt", "a");//a是不断写入txt文件,不覆盖前面的内容,###是你的输出的文件名
fprintf(input, "***");//***是你要输出的信息
 fclose(input);

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用类似的方法将函数的输出结果显示在 `QTextBrowser` 中。以下是一个简单的示例代码: ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QTextBrowser from io import StringIO class Stream(QObject): """将print输出重定向到QTextBrowser的流""" newText = pyqtSignal(str) def write(self, text): self.newText.emit(str(text)) class MainWindow(QMainWindow): def __init__(self): super().__init__() self.textBrowser = QTextBrowser(self) self.setCentralWidget(self.textBrowser) sys.stdout = Stream(newText=self.onUpdateText) # 假设您的函数名为 my_function self.my_function() def my_function(self): # 模拟函数输出 output = StringIO() sys.stdout = output print("Hello World") print("This is a test") sys.stdout = sys.__stdout__ # 将输出文本添加到 QTextBrowser 中 text = output.getvalue() self.textBrowser.append(text) @pyqtSlot(str) def onUpdateText(self, text): """将文本添加到 QTextBrowser""" cursor = self.textBrowser.textCursor() cursor.movePosition(QTextCursor.End) cursor.insertText(text) self.textBrowser.setTextCursor(cursor) self.textBrowser.ensureCursorVisible() if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) ``` 这个代码定义了一个 `Stream` 类,这个类重写了 `write()` 方法并且使用 `pyqtSignal` 将输出文本发送到 `MainWindow` 类的 `onUpdateText` 槽函数。在 `MainWindow` 类中,我们将 `sys.stdout` 重定向到 `Stream` 类的实例上,这样所有的 `print` 输出都会被发送到 `onUpdateText` 槽函数中,然后将文本添加到 `QTextBrowser` 中。在 `my_function` 函数中,我们使用 `StringIO` 模块模拟函数的输出结果,并且将结果添加到 `QTextBrowser` 中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值