我是 C++ 新手。我通常用 C# 编程,所以我在使用数组和循环时遇到了麻烦。当我尝试使用循环打印动态数组的内容时,它说请求的区域已损坏...例如,我将让它识别与数组内容一起使用的条件,但不打印它的内容:
// Array.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
int size=3;
int *p;
int myarray[10];
myarray[3]=4;
p=new int[size];
p[2]=3;
if(myarray[3]==4){
cout << myarray[3] +"/n";
cout << "Why?";
}
else
cout << "Not equal " << endl;
cin.get();
delete [] p;
}