在我的书中有一个示例如何复制一个字符串(2个指针)。我复制了整个代码,但是当我在终端中启动程序时,它说“分段错误(核心转储)”>。 <我的C++代码有什么问题?
这段代码有什么问题? :
#include <iostream>
#include <string>
using namespace std;
void cpy(char* p,const char* q){
while(*p++ = *q++) ;
}
int main(){
char* hello;
cpy(hello, "Whazzap");
return 0;
}
你应该去读一本好的C++书籍,这会让你开始。 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – inf 2013-03-15 18:14:25
你在用什么书? – Beta 2013-03-15 18:15:00
@bamboon我想我正在用一本非常好的书 - Bjarne Stroustrup(C++的创建者)的“C++编程语言” – 2013-03-15 18:17:37