C++读取C#的byte[]文件
// 指定要读取的文件路径和名称const char* filePath = "D:\\2-LearningCode\\902-ASR\\Github\\Model\\output.bin";
// 使用ifstream以二进制模式打开文件
//std::ifstream file(filePath, std::ios::binary);
std::ifstream file(filePath, std::ios::binary);
// 移动到文件末尾以获取文件大小
file.seekg(0, std::ios::end);
std::streamsize fileSize = file.tellg();
file.seekg(0, std::ios::beg);
// 分配足够的空间来存储文件内容
std::vector<unsigned char> buffer(fileSize);
// 读取文件内容到vector<unsigned char>中
if (!file.read(reinterpret_cast<char*>(buffer.data()), fileSize))
{
std::cerr << "读取文件时出错" << std::endl;
return 1;
}
// 输出读取到的数据
//for (const auto& b : buffer)
//{
// std::cout << std::hex << static_cast<int>(b) << " "; // 以十六进制格式输出
//}
//std::cout << std::endl;
file.close(); // 关闭文件
// 此时,buffer包含文件的内容,可以像使用unsigned char*一样使用它
unsigned char* data = buffer.data();
std::cout << fileSize << std::endl;
char* output1 = PredictASRBytes_GPU(data, 179778, 16000, 0.02, 0.01);
std::cout << output1 << std::endl;
在C#中,使用File.WriteAllBytes方法写入一个二进制文件;File.ReadAllBytes方法来读取整个文件内容到一个字节数组中。
页:
[1]