我正在尝试将结构保存到文件中,然后在另一个程序中再次读取它。我以前从未遇到过此问题,但至少据我所知,我从未尝试将带有值的双变量写入56.806201550387598文件。并不是说我不知道为什么这个数字会产生任何问题,但是每当我尝试将包含该值的结构写入文件时,该字段及其后声明的任何字段都只能从该结构中读出初始化值宣言。
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
typedef struct statsSet{
int pathCount = 0;
double vMinMean = 0;
int imgsFound = 0;
int minWidth = INT_MAX;
int maxWidth = 0;
}statsSet;
void wrightToFile(statsSet sSet){
FILE* of = fopen ("imgStats2.dat", "w");
fwrite (&sSet, sizeof(statsSet), 1, of);
fclose (of);
}
statsSet readFromFile(){
statsSet statReadIn;
FILE *ifl = fopen ("imgStats2.dat" , "r");
fread(&statReadIn, sizeof(statsSet), 1, ifl);
fclose (ifl);
return statReadIn;
}
void pr(statsSet statReadIn){
cout << "pathCount: " …Run Code Online (Sandbox Code Playgroud)