C 高分列表调试错误

C++ Highscore List Debug Error

本文关键字:调试 错误 列表      更新时间:2023-10-16

编辑代码:我现在能够在文件中写入时钟时间,但是问题是,这不是时钟时间。它写入奇怪的数字,例如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)
    {
}

您的highscore结构中有string clockstring类型的对象不适合直接从内存中写入文件,因为它们可能包含到内存其他部分的指针。

这里有两个解决方案:要么像其他结构成员一样将clock更改为char数组,要么不使用高分的二进制写作,请将文件写为文本(这更复杂,但导致了一个人类可读文件)。

您是否在创建文件后设置了文件权限?似乎将权限设置为没有读取,没有写,没有执行。