我一直在这里坐了几个小时试图弄清楚这一点。我一直无法找到类似的问题(尽管我确信它已经完成)。所以在我的问题。当我编译这个时,它很好。
我应该补充说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)抛出:0000005:访问冲突写入位置00000000。
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
{
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);
}
请帮助欧比旺。你是我唯一的希望...
你的变量'unsortedArrayLength'是一个常量吗?如果不是,你可能会遇到数组被正确初始化的问题,实际上,我也不确定为什么你会使用数组长度变量作为索引,这会使你返回1个索引超过数组的末尾,这是一个经典的“一个一个”的错误,你可能需要发布更多关于你设计的方式的信息你的数组和索引它的方式 – ciphermagi
我只是要编辑unsortedList的类型为Book *。我的索引== 1.在另一个函数中,前一个操作的索引处有一个对象 – yorTsenoJ
请包括struct Book的定义 – ciphermagi