error C2440: “类型转换”: 无法从“stu_a”转换为“stu_b”

环境:win10+vs2017

// main.c
typedef struct test
{
	int m;
} stu_a, stu_b;

int main()
{
	stu_a m;
	stu_b n = (stu_b)m;
	return 0;
}

编译报错:error C2440: “类型转换”: 无法从“stu_a”转换为“stu_b”

原因:C语言中的结构体并不能直接进行强制类型转换,只有结构体的指针可以进行强制类型转换。

参考:https://learn.microsoft.com/zh-cn/cpp/error-messages/compiler-errors-1/compiler-error-c2440?view=msvc-170

https://www.cnblogs.com/amxiang/p/16948916.html

生成一个python脚本,要求实现以下功能: 1.利用Python PIL 库实现对特定文件夹内图片文件图片格式进行转换并批量重命名, 重命名的名称要求用户输入.脚本参考如下:import os import PIL import fnmatch from PIL import Image # 源目录 source_dir = 'E:\Stu_2025_01\视觉设计制作-张诗军\C4D课件图\LogoPictures' # 目标目录 target_dir = 'E:\Stu_2025_01\视觉设计制作-张诗军\C4D课件图\P_lp' # 遍历源目录中的所有DDS\png\jpg文件 for filename in os.listdir(source_dir): if filename.endswith(('.DDS','.PNG', '.jpg', '.JPG', '.png', '.dds','.webp')): # 检查是否为需要更改文件格式 original_path = os.path.join(source_dir, filename) new_filename = filename[:-4] + '.jpg' # or filename[:-4] + '.png' # 新文件名,转换成.jpg或.png try: with Image.open(original_path) as img: # 转换为JPEG # 颜色模式转换RGB/CMYK img_jpeg = img.convert('RGB') # img_jpeg = img.convert('CMYK') target_path = os.path.join(target_dir, new_filename) img_jpeg.save(target_path) print(f"Converted {original_path} to {target_path}") # IO处理 except IOError: print(f"Error converting {original_path}") # 统计同类型文件数目 def count_files_by_type(directory, file_type): count = 0 for root, dirs, files in os.walk(directory): for name in files: if fnmatch.fnmatch(name, file_type): count += 1 return count # 使用函数,统计当前目录下的所有想要统计的文件 file_count = count_files_by_type('E:\Stu_2025_01\视觉设计制作-张诗军\C4D课件图\P_lp', '*.jpg') print(f'There are {file_count} .jpg files.')
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值