volvox
小水手

UID 30750
精华
0
积分 1
帖子 1
阅读权限 10
注册 2007-11-18
状态 离线
|
请教关于程序运行的故障,谢谢!
本人是个C++新手,在国外打工,被可恶的BOSS赶鸭子上架编了一个小程序,可是好
象运行不正常,请高手帮忙指点一下.
程序要求:
1.Ask the user how long their name is (问用户的名字是几个字母)
2.Create an array of chars in dynamic memory large enough to store the
name
3.Ask the user to enter their name
4.Read the name into the array (assume it may include spaces)本人试了又
试,好象找不到合适的方法实现这一要求.
5.Output the name
6.Delete the array from dynamic memory
程序如下:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int n;
char *a;
cout<<"How many character of your name ";
cin>>n;
int m=n+5;
a=new char[m];
cout<<"Pleas enter your name: ";
cin.get(a,m);//此处能编译但无法运行,程序运行到此便结束
cout << a;
delete[] a;
system("PAUSE");
return 0;
}
故障
见倒数第七行中的"//"注明
请高手帮忙!!!不胜感激.
|  勿忘国耻,抵制日货 |
|