如何打开读取16位.raw文件Vc++(Wince平台)
How to open and read 16 bit .raw file Vc++ (Wince platform)
我正在尝试在 Wince 平台上使用 c++ (visual studio 2013) 读取 16 位 .raw 文件。但不确定 api 应该用于打开和读取操作。它似乎对图像文件的文件操作不同于 .txt 文件。请帮助我获取读取 16 位原始数据的示例代码。
寻址 C
标签:
注意:以下代码在 C 中运行良好,也可以在(但不是最佳的)c++ 中编译。
如果用 C 编码,则使用 fopen(,) is a good option, and the 2nd argument is key as it sets the function to perform several variations of opening a file, including binary reads. The following excerpt is one of several sections provided in the C Tutorial – Binary File I/O:
#include<stdio.h>
/* Our structure */
struct rec
{
int x,y,z;
};
int main()
{
int counter;
FILE *ptr_myfile;
struct rec my_record;
ptr_myfile=fopen("test.bin","rb");//note the argument 'rb' for read binary
if (!ptr_myfile)
{
printf("Unable to open file!");
return 1;
}
for ( counter=1; counter <= 10; counter++)
{
fread(&my_record,sizeof(struct rec),1,ptr_myfile);
printf("%d\n",my_record.x);
}
fclose(ptr_myfile);
return 0;
}
我正在尝试在 Wince 平台上使用 c++ (visual studio 2013) 读取 16 位 .raw 文件。但不确定 api 应该用于打开和读取操作。它似乎对图像文件的文件操作不同于 .txt 文件。请帮助我获取读取 16 位原始数据的示例代码。
寻址 C
标签:
注意:以下代码在 C 中运行良好,也可以在(但不是最佳的)c++ 中编译。
如果用 C 编码,则使用 fopen(,) is a good option, and the 2nd argument is key as it sets the function to perform several variations of opening a file, including binary reads. The following excerpt is one of several sections provided in the C Tutorial – Binary File I/O:
#include<stdio.h>
/* Our structure */
struct rec
{
int x,y,z;
};
int main()
{
int counter;
FILE *ptr_myfile;
struct rec my_record;
ptr_myfile=fopen("test.bin","rb");//note the argument 'rb' for read binary
if (!ptr_myfile)
{
printf("Unable to open file!");
return 1;
}
for ( counter=1; counter <= 10; counter++)
{
fread(&my_record,sizeof(struct rec),1,ptr_myfile);
printf("%d\n",my_record.x);
}
fclose(ptr_myfile);
return 0;
}