C++中的类型转换static_cast
C++ 类型转换 static cast
2023-09-11 14:14:48 时间
// Compose.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <vld.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
#define Byte50M 52428800
#define HeadEnd 0xFF
typedef struct sonfile
{
unsigned char sum; //总共分成多少个文件
unsigned char order;//子文件在原文件中的顺序
char* source; //原文件名
};
int sfheadsize(char* filename);
sonfile readsfhead(char* filename);
int main(int argc,char* argv[])
{
if (argc < 1)
exit(-2);
for (int i = 1; i < argc; i++)
{
printf("head size:%d file:%s\n", sfheadsize(argv[i]), argv[i]);
sonfile sf = readsfhead(argv[i]);
printf("sonfile.sum:%d\nsonfile.order:%d\nsonfile.source:%s\n", sf.sum, sf.order, sf.source);
}
return 0;
}
int sfheadsize(char* filename)
{
FILE* fp = fopen(filename, "r");
char temp = '\0';
int count = 0;
do
{
fread(&temp, 1, 1, fp);
++count;
if (temp == EOF)
break;
} while (temp != HeadEnd);
fclose(fp);
return count;
}
sonfile readsfhead(char* filename)
{
sonfile sf;
memset(&sf, 0, sizeof(sf));
FILE* fp = fopen(filename, "r");
char temp = '\0';
fread(&temp, 1, 1, fp);
sf.sum = static_cast<unsigned char>(temp);
fread(&temp, 1, 1, fp);
sf.order = static_cast<unsigned char>(temp);
stringstream sstr;
string srcfname;
do
{
fread(&temp, 1, 1, fp);
sstr << temp;
sstr >> srcfname;
#ifdef _DEBUG
printf("0x%02h ", temp);
#endif //_DEBUG
if (temp == EOF)
break;
} while (temp != HeadEnd);
#ifdef _DEBUG
cout << srcfname << endl;
#endif //_DEBUG
fclose(fp);
return sf;
}
相关文章
- C++处理char*,char[],string三种类型间的转换
- C++之MutexLock和MutexLockGuard封装
- 自己实现c++中string 类
- qt实现web服务器加载vue应用进行C++和html混合编程-连载【6】-企业级系统开发实战连载系列 -技术栈(vue、element-ui、qt、c++、sqlite)
- C++类型转换
- [c++菜鸟]《Accelerate C++》读书笔记
- c++之默认参数
- Unreal新建C++类或C++项目失败
- 43 C++ - 派生类访问控制
- c++STL map(映射)容器总结
- C++中对于类来说头文件(.h)和源文件(.cpp)都应该写些什么 (类的常规创建)
- C++常用类型转换
- [C++]:万字超详细讲解多态以及多态的实现原理(面试的必考的c++考点)
- C/C++中的数据类型转换()/static_cast/dynamic_cast/const_cast/reinterpret_cast
- C/C++中有符号数隐式类型转换成无符号数需注意的问题
- 使用c++filt命令还原C++编译后的函数名
- 《C++编程惯用法——高级程序员常用方法和技巧》——2.4 隐式类型转换
- 基于C++实现页面的缓冲区管理器【100010158】
- C/C++函数调用约定与this指针
- [第八届蓝桥杯省赛C++A/B组]分巧克力
- C++库大全(转)
- C/C++教程 第二十一章 —— Qt界面开发