我創建了一個結構指針。併爲其分配值。我試圖打印分配給它的值。它抱怨未處理的異常訪問衝突寫入位置0xCDCDCDCD。這樣做有什麼問題?如何無一例外地完成這項任務?所有的未處理的異常訪問衝突寫入位置0xCDCDCDCD - 結構C++
StructCol.h
#include "stdafx.h"
#ifndef StructCol_H
#define StructCol_H
#include<string>
using namespace std;
struct ABC
{
string test;
int no;
void print()
{
cout << test << endl;
cout << no << endl;
}
};
#endif
StructTest2.cpp
#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<stdio.h>
#include "StructCol.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ABC*abc = (ABC*)malloc(sizeof(ABC));
abc->no = 47;
abc->test = "fyp";
abc->print();
//delete abc;
//abc->print();
_getch();
return 0;
}
即使出題的正確建議 – Veena