XiaoHui.net 笑汇程序员论坛首页
工作并快乐着,职业并休闲着
寻梦的岁月从不言辛苦几许,
不问收获几多……
» 游客:  申请新用户 | 登录 | 会员 | 统计 | 帮助 » XiaoHui.Net 笑汇程序员论坛 | 纯文字版 | 全站索引 | XiaoHui.com


[编译器调试] 请教关于程序运行的故障,谢谢!

RSS 订阅当前论坛  

上一主题 下一主题
     

标题: [编译器调试] 请教关于程序运行的故障,谢谢!  
 
volvox
小水手
Rank: 1



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;
}



故障

见倒数第七行中的"//"注明


请高手帮忙!!!不胜感激.


勿忘国耻,抵制日货
2007-11-18 14:07#1
查看资料  Blog  发短消息  顶部
 
筱湖
小水手
Rank: 1


UID 30766
精华 0
积分 1
帖子 1
阅读权限 10
注册 2007-11-21
来自 盐城
状态 离线
修改

#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();
  cin.getline(a,m);//此处能编译但无法运行,程序运行到此便结束
  cout << a;
      
  delete[] a;
  system("PAUSE");
  return 0;
}
2007-11-21 19:02#2
查看资料  Blog  发短消息  QQ  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题  


 


所有时间为 GMT+8, 现在时间是 2008-12-2 09:40 Powered by Discuz! 4.1.0 清除 Cookies - XiaoHui.Net 笑汇程序员论坛 - Archiver