将数据写成txt要注意的地方

你的数据是n行,每行数据间是一个空格隔开,并且末尾不要有空格!!!末尾是换行符。而且每行都要有数据,最好不要空出某行不要空出第一行

   // 打开txt文件写入
    FILE* output = NULL; 
    fopen_s(&output, outFielName, "w");
    fseek(fp, 0, SEEK_END);
    long fsize = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    VelHeader velHeaderInfo;
    int index = 0;

    double dep = readdouble8(fp);
    fprintf(output, "%.5lf ", dep);
    while (!feof(fp))
    {   
        if (index != 0)// 去除首行空行
        {
            double dep = readdouble8(fp);
            fprintf(output, "\n%.5lf ", dep);
        }
        
        for (int j = 0; j < nwf_L; j++)
        {
            long remaining = fsize - ftell(fp) ;
            // std::cout << remaining << std::endl;
          
            if (remaining <= 266) // 文件末尾有信息,但是实现被封装了,无法查看,具体多长不知道
            {// 文件末尾
                
                 
                const int size = remaining;
                char* buff = (char*)alloca(remaining * sizeof(char)) ;

                int len = fread(buff, 1, remaining, fp);

                for (int i = 0; i < len; i++) {
                    printf("%02x ", buff[i]);
                }
               // 直接打印字节
                char t;
                while (fscanf_s(fp, "%c", &t) != EOF) { 
                    std::cout << "." << t; 
                } 
                 
                return;
            }
            else
            {
                float velo = readfloat4(fp);
                if (j == nwf_L - 1)// 行尾,去空格
                {
                    fprintf(output, "%.5f", velo);
                }
                else
                {
                    fprintf(output, "%.5f ", velo);
                }
                
            }
        }
        index++;
    }
    fclose(fp);
    fclose(output);

你可能感兴趣的:(总结记录c++,c++,算法,开发语言)