成功生成没有警告,为什么无法运行

pzh2386034 2009-10-31 01:10:39
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace System;
using namespace std;

int main(array<System::String ^> ^args)
{
int numble=3;
char **string = new char *[numble];

cout<<"Please input string";
cin.getline(string[0],20);
cin.getline(string[1],20);
cin.getline(string[2],20);
cout<<"第一种程序语言: "<<" "<<string[0]<<endl;
cout<<"第二种程序语言: "<<" "<<string[1]<<endl;
cout<<"第三种数据库 : "<<" "<<string[2]<<endl;
for(int i=0 ; i<numble ; i++){
delete string[i];
}
delete *string;


return 0;
}
高手看看这个程序,成功生成了,没有警告,但却无法运行!!!
...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cphj 2009-10-31
  • 打赏
  • 举报
回复
你ptr += 5;导致ptr越界了,访问*ptr就可能导致程序崩溃

把ptr += 5;和ptr --;都去掉
pzh2386034 2009-10-31
  • 打赏
  • 举报
回复
谢谢2楼~加上你给的代码就OK了。有空再帮我看看这个
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace System;
using namespace std;

int main(array<System::String ^> ^args)
{
int i = sizeof(int);
int *ptr = (int*) 1200;
ptr += 5;
cout<<ptr<<endl;
ptr --;
cout<<&ptr<<" "<<ptr<<" "<<i<<" "<<*ptr;


return 0;
}也是一样问题
运行到"<<*ptr; 就停止运行了。*ptr要是有问题该怎么让他显示ptr所指向的内存
万分感谢
jackyjkchen 2009-10-31
  • 打赏
  • 举报
回复
而且,没事不要用C++.net的项目,应该用win32控制台
jackyjkchen 2009-10-31
  • 打赏
  • 举报
回复
二级指针,你只分配了一层
还要加个
for(int i=0; i<numble; i++)
string[i] = new char[21];

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧