写入对象时运行时引发异常错误
Exception thrown error at runtime when writing to object
我已经坐在这里几个小时了,试图弄清楚这一点。我无法找到类似的问题(尽管我确定已经完成了)。所以关于我的问题。当我编译这个时,它很好。
我应该补充一点,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;
但是,当我编译它时,我收到一个错误:
在分配.exe:0xC0000005:访问冲突写入位置0x00000000中0x5AC6516F (vcruntime140d.dll) 引发异常。
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);
}
请帮助欧比旺。你是我唯一的希望...
好吧,我想通了。我使数组的实例化更大。看来我正在达到阵列的上限。数组用 2 初始化,虽然这就足够了,但事实并非如此。 :(感谢大家把他们的知识借给我。
相关文章:
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- 打开CV异常错误,尽管我的代码是正确的
- 异常错误C++ //Visual Studio
- 提升序列化异常错误
- 返回内存异常错误的矢量
- 使用用户定义的函数查找完美数时出现浮点异常错误
- cv::内存位置出现异常错误
- OpenCV未经处理的异常错误
- 分数简化算法,浮点异常错误
- 为什么我会收到浮点异常错误
- 文本框为空时,C++Windows窗体应用程序出现未处理的异常错误
- 文本框为空时C++ Windows 窗体应用程序未处理的异常错误
- 函数传递映射时出现异常错误
- 在MS Visual Studio 2010上使用带有Cuda互操作的OpenGL缓冲区时出现异常错误
- 未处理的异常错误
- C++:关闭控制台应用后出现异常错误
- 写入对象时运行时引发异常错误
- C++ C# 包装器空异常错误
- Coin3D(Open Inventor)中出现未处理的异常错误
- Stack Pop()函数出现未处理的异常错误