帮忙看一段C++程序,纠错

来源:百度知道 编辑:UC知道 时间:2024/05/11 00:38:57
.h文件是:
#include<iostream.h>
class astring
{
private:
int length;
char*contents;
public:
int get_length()
{return length;}
char*get_contents()
{return contents;}
void set_contents(char*in_contents)
{
contents=in_contents;
int len=0;
while(*in_contents++!='\0')
len++;
length=len;
}
}
.cpp文件是
#include"astring.h"
#include<iostream.h>
int main()
{
astring obj;
obj.set_contents("hello,world");
int a=obj.get_length();
char*p=obj.get_contents();
cout<<a<<endl<<p;
return 0;
}

编译又一个错,错误信息是
astring.cpp(3) : error C2143: syntax error : missing ';' before 'PCH creation point'
执行 cl.exe 时出错.
帮忙修改下,谢谢!

头文件中,类声明最后忘了加分号了,加上就好了

去掉astring.cpp中的#include<iostream.h>
你的astring.h中已经包含此文件了

楼上说的也是一个错误