流到字节数组
我正在用本机 C++ 创建一个程序(无 clr)。我正在使用一个工具包来转换数据并通常将其写入文件或标准输出。 问题是我想将其写入数组,但我不知道将发送的大小。 该工具包需要参数“FILE *”且无法修改。
基本上工作代码:
FILE * ofile = fopen("yourfile.dat", "wb");
toolkit::function(ofile);
fclose(ofile);
std 输出第一行就是
FILE * ofile = stdout;
我现在想要的,是我可以执行函数 end 最后有一个指向数组操作字节(例如 char *)及其大小的指针。 我一直在四处寻找可以找到解决方案。 首先写入文件不是一个选项。
I'm creating a program in native C++ (no clr). I'm using a toolkit which converts data and normally writes it to a file or stdout.
The issue is that I want to write it to an array and I don't know the size which will be sent.
The toolkit requires a paramter "FILE *" and cannot be modified.
Basically working code:
FILE * ofile = fopen("yourfile.dat", "wb");
toolkit::function(ofile);
fclose(ofile);
to std out the first line would be
FILE * ofile = stdout;
What I want now, is that I have can perform the function end in the end have a pointer to an array op byte (e.g. char *) and the size of it.
I've been looking around an can find the sollution.
First writing to a file is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没理解错的话,您需要一个 FILE* 对象来存储写入内存缓冲区中的所有字节,对吧?
fmemopen
正是完成这项工作,但它是 POSIX.1-2008 并且根据其联机帮助页并未广泛使用。If I got you right, you want a FILE* object that will store all bytes that were written to it in a memory buffer, right?
fmemopen
does exactly this job, but is POSIX.1-2008 and according to its manpage not widely available.