我正在写一个简单的程序.里面只有一节课.有一个私人成员'char*号码'和两个功能(会有更多,但首先这些应该正常工作:)).
第一个应该将'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
}
Run Code Online (Sandbox Code Playgroud)
和打印功能:
void LongNumber::print(){
cout<<number<<endl;
// when I try to print with the same line of code here..it crashes
}
Run Code Online (Sandbox Code Playgroud)
当然,我错过了什么......但是什么?
(因为这是我的第一篇文章......你认为标签是否已经更正......你会如何标记帖子?)
先感谢您 :)