【发布时间】:2009-06-28 07:19:57
【问题描述】:
我正在编写一个简单的程序。里面只有一门课。有一个私有成员 'char * number' 和两个函数(会有更多,但首先这些应该可以正常工作:))。
第一个应该将'source'复制到'number'变量中(我想这里的某个地方是问题):
LongNumber::LongNumber(const char * source ){
int digits = strlen(source);
char* number = new char[digits+1];
strcpy( number, source );
// cout<<number<<endl; - if the line is uncommented,
// the output is correct and there isn't a problem
}
还有一个打印功能:
void LongNumber::print(){
cout<<number<<endl;
// when I try to print with the same line of code here..it crashes
}
当然,我错过了什么……但是什么?
(因为这是我的第一篇文章……您认为标签是否已更正……您将如何标记该帖子?)
提前谢谢你:)
【问题讨论】:
标签: c++ printing pointers char