警告:c++中的system()

warning: for system() in c++

本文关键字:system 中的 c++ 警告      更新时间:2023-10-16

我有一个c++程序
我通过system();函数调用ImageMagick command
它工作在一些简单的命令
但是当我调用这个命令

sprintf(command, "convert -threshold 25% f1/file%.3d.png f2/file%.3d.png", num,num);
system(command);

它给我警告说

warning: format ‘% f’ expects type ‘double’, but argument 3 has type ‘int’

我知道因为%在命令25 % f 1有不同的意义

您必须写25%%而不是25%.以转义'%'符号

如果需要包含%字符,则使用%%:

sprintf(command, "convert -threshold 25%% f1/file%.3d.png f2/file%.3d.png", num,num);

为了获得字面上的百分号,需要写%%,即在您的情况下:

sprintf(command, "convert -threshold 25%% f1/file%.3d.png f2/file%.3d.png", num,num);