我已经坐在这里几个小时试图弄清楚这一点。我还没有找到类似的问题(尽管我确信它已经完成了)。那么关于我的问题。当我编译它时,它很好。
我应该补充一点,unsortedList 是 Book*,它是一个结构。
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title;
unsortedList[unsortedArrayLength].action;
unsortedList[unsortedArrayLength].author;
unsortedList[unsortedArrayLength].subject;
unsortedList[unsortedArrayLength].time;
但是,当我编译它时,我收到一个错误:
Assign.exe 中的 0x5AC6516F (vcruntime140d.dll) 抛出异常:0xC0000005:访问冲突写入位置 0x00000000。
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title = tit;
unsortedList[unsortedArrayLength].action = act;
unsortedList[unsortedArrayLength].author = aut;
unsortedList[unsortedArrayLength].subject = sub;
unsortedList[unsortedArrayLength].time = tm;
然后它会弹出 memcpy.asm 窗口,光标在这个位置:
CopyUpByteLoop:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi
dec ecx
jne CopyUpByteLoop
按要求定义 struct Book:
struct Book
{
std::string title;
std::string author;
std::string subject;
char* time;
std::string action;
};
这是完整的功能:
void DB::insertBook(Book* tempBook)
{
using namespace std;
unsortedArrayLength++;
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title = tit;
unsortedList[unsortedArrayLength].action = act;
unsortedList[unsortedArrayLength].author = aut;
unsortedList[unsortedArrayLength].subject = sub;
unsortedList[unsortedArrayLength].time = tm;
system("cls");
cout << "You have " << unsortedList[unsortedArrayLength].action <<":\n" << endl <<
unsortedList[unsortedArrayLength].title << endl <<
unsortedList[unsortedArrayLength].author << endl <<
unsortedList[unsortedArrayLength].subject << endl <<
"on " << unsortedList[unsortedArrayLength].time << endl << endl;
printToLog(tempBook);
}
请帮助欧比旺。你是我唯一的希望...