在C++中使用带有sprintf()的格式字符串的警告

Emi*_*lio 2 c++ format printf types

编译这一行

    long int sz;
    char tmpret[128];

    //take substring of c, translate in c string, convert to int, 
    //and multiply with 1024
    sz=atoi(c.substr(0,pos).c_str())*1024;

    snprintf(tmpret,128,"%l",sz); 
Run Code Online (Sandbox Code Playgroud)

我在snprintf上读了两个警告:

 warning: conversion lacks type at end of format
 warning: too many arguments for format
Run Code Online (Sandbox Code Playgroud)

为什么?指定了类型(long int sz和snprintf中的%l),snprintf中的参数只有一个.有谁能够帮我?谢谢.

Dmi*_*tov 8

您的格式缺少类型,因为l是"sizeof"修饰符.应该是%ld