什么是写入到二进制模式标准输出最简单的方法? [英] What is the simplest way to write to stdout in binary mode?

查看:157
本文介绍了什么是写入到二进制模式标准输出最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出写二进制数据从一个C程序到标准输出的最佳途径。它适用于Linux的罚款,但我有问题,当我在Windows上编译,因为\\ n被转换为\\ r \\ n。

I've been trying to figure out the best way to write binary data to stdout from a C program. It works fine on Linux, but I'm having issues when I compile on Windows because "\n" gets converted to "\r\n".

有没有写在标准输出某种二进制模式避免了换行转换的标准方式?如果没有,是什么让Windows停止这样做最简单的方法是什么?

Is there a standard way to write to stdout in some sort of binary mode which avoids newline conversion? If not, what is the simplest way to get Windows to stop doing this?

我使用GCC和MinGW。

I'm using GCC and MinGW.

推荐答案

您可以使用 setmode(的fileno(标准输出),O_BINARY)

把它包在IFDEF,如果你想保持它兼容Linux。

Wrap it in an ifdef if you want to keep it compatible with Linux.

又见<一个href=\"http://msdn.microsoft.com/en-us/library/tw4k6df8(v=vs.80).aspx\">http://msdn.microsoft.com/en-us/library/tw4k6df8(v=vs.80).aspx

这篇关于什么是写入到二进制模式标准输出最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆