int64 c++ debian6

int64 c++ debian6

本文关键字:debian6 c++ int64      更新时间:2023-10-16

为什么我不能得到这个int64工作?我用c++ -x编译c++ - 0程序源。c它一直从-2147483648开始,高于2147483647 ....

#include <stdint.h>
#include <inttypes.h>
#ifdef __cplusplus
#include <cstdio>
#include <cstdlib>
#include <cstring>
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
int main(int argc, char* argv[])
{
    int64_t i;
    for(i = 0; i < argc; ++i)
        printf("argv[%d]: %sn", i, argv[i]);
    char string [512];
    int64_t a1 = atoi((const char*) gets(string));
    int64_t limit = a1 + 99999999999
    while(a1 <= limit)
    {
        char command[10000];
        sprintf(command, "%d", a1);
        FILE* pFile = fopen ("myfile.txt","wa");
        fprintf (pFile, "%sn", command);
        fclose (pFile);
       a1= a1 + 4321;
    }
    return EXIT_SUCCESS;
}
c

我认为你应该替换

sprintf(command, "%d", a1);

sprintf(command, "%lld", a1);

使用错误的格式说明符是未定义的行为。AFAIK,在gcc中使用%d作为格式说明符只强制输出32位-因此导致输出文件中看起来像溢出。

int64_t limit = a1 + 99999999999;

整型常量太大

相关文章: