我在写一个简单的程序。它只有一个类。有一个私人成员'char * number'和两个函数(会有更多,但首先这些应该正常工作:))。在C++中打印char *
第一个应该复制的“源”到“数字”变量(和我想的地方现在的问题):
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
}
当然,我错过了一些东西......但是什么?
(由于这是我的第一篇......你认为标签corrected..how将您所标记的职位?)
预先感谢您:)
哎呀,似乎有一百万人回答了这个问题,而我......对不起,关于这个:) – micmoo 2009-06-28 07:30:45