gpt4 book ai didi

c++ - C/C++ 中的并行数据到串行 : Implementing a multiplex

转载 作者:行者123 更新时间:2023-11-30 17:43:22 24 4
gpt4 key购买 nike

我开始致力于用 C 或 C++ 实现基本并行串行数据转换器 (MUX)。基本上,该程序从某些文件中获取数据并在单个文件中串行显示它们。

我就从这个开始,在网上搜索了一下,没有找到太多信息。
有我可以使用的图书馆吗?或者有什么建议或指南吗?
如果您有一些信息,无论编程语言如何,请分享。

最佳答案

假设您想打开许多文件并将其内容写入单个文件,请尝试如下操作:

#include <iostream>
#include <fstream>

using std::ifstream;
using std::ofstream;
using std::cout;
using std::cerr;

int main(void)
{
// Open the files.
ifstream file_1("file_001.bin", ios::binary);
if (!file_1)
{
cerr << "Error opening first file.\n";
return EXIT_FAILURE;
}
//...
ofstream serial_file("serial_result.bin", ios::binary);
if (!serial_file)
{
cerr << "Error opening serial result file.\n";
return EXIT_FAILURE;
}

// Read from the files
unsigned char byte;
while (file_1.read(&byte, 1))
{
// Write to serial file.
serial_file.write(&byte, 1);
// Read byte from next file
file_2.read(&byte, 1);
serial_file.write(&byte, 1);
// Etc.
}
return EXIT_SUCCESS;
}

关于c++ - C/C++ 中的并行数据到串行 : Implementing a multiplex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20247929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com