编辑代码:我现在可以在文件中写入时钟时间,但问题是,它并不完全是时钟时间。它会写一些奇怪的数字,比如00F3D。诸若此类。我不知道它是否是到期的,因为当它是字符串格式时,时钟的时间包含一个冒号,例如: 0:12
// Used for Highscores
struct highscore
{
char name[10];
int zombiesKilled;
char Date[10];
char *clock[10];
};
void highscoreBoard(int option, int zombKilled)
{
int quanity = 0;
int playerScore = 0; // the in Results for Highscores
FILE *streaming;
highscore data[10];
char *newClock = new char[clockData.clockTime.length() + 1];
strcpy(newClock,clockData.clockTime.c_str());
switch (option)
{
}发布于 2015-05-09 10:19:07
您的highscore结构中包含string clock。string类型的对象不适合直接从内存写入文件,因为它们可能包含指向内存其他部分的指针。
这里有两个解决方案:要么像其他结构成员一样将clock更改为字符数组,要么不使用高分的二进制写入,而是将文件写为文本(这会更复杂,但会生成人类可读的文件)。
发布于 2015-05-09 09:34:42
创建文件后是否设置了文件权限?权限似乎已被设置为无读、无写、无执行。
https://stackoverflow.com/questions/30135037
复制相似问题