| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 685 人关注过本帖
标题:新生的问题,弄了好不久,不能编译通过,大家看一看,在线等!!
只看楼主 加入收藏
liujianlin
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-11-11
收藏
 问题点数:0 回复次数:2 
新生的问题,弄了好不久,不能编译通过,大家看一看,在线等!!
//类定义 stringbad.h
#include<iostream>
using namespace std;
#ifndef stringbad_H_
#define stringbad_H_
class stringbad
{
private:
 char *str;
 int len;
 static int num_strings;
public:
 stringbad();
 stringbad(const char *s);
 ~stringbad();
 //friend function
 friend ostream &operator<<(ostream &os,const ostream &st);
};
#endif
//类方法 stingbad.cpp
#include<iostream>
#include<cstring>
#include"stringbad"
using namespace std;
int stringbad::num_strings=0;//初始华静态数
stringbad::stringbad()
{
 len=4;
 str=new char[4];
 strcpy(str,"C++");
 num_strings++;
 cout<<num_stirngs<<":\"<<str<<"defaultt object created";
}
stringbad::stringbad(const char *s)
{
 len=strlen(s);
 str=new char[len+1];
 strcpy(str,s);
 num_strings++;
 cout<<num_strings<<":\"<<str<<"object created"<<endl;
}
stringbad::~stringbad()
{
 cout<<"\"<<str<<"\"object delete"<<endl;
    --num_strings;
 cout<<num_strings<<"left\n";
 delete [] str;
 
}
ostream &operator<<(ostream &os,const stringbad & st)
{
 os<<st.str;
 return os;
}
//主函数
#include<iostream>
#include"stringbad.h"
using namespace std;
//void callme1(stringbad &);
//void callme2(stringbad);
int main()
{
 stringbad headline1("Celery Stalks at Midnight");//创建一个headline1对象
 stringbad headline2("lettuce Prey");
 stringbad sports("Spinach Leaves Bow1 for Dollars");
 cout<<"headline1"<<headline1<<endl;
 cout<<"headline2"<<headline2<<endl;
 cout<<"sprots"<<sports;
 return 0;
}
搜索更多相关主题的帖子: 新生 编译 在线 
2007-11-27 20:58
ml232528
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:367
专家分:879
注 册:2007-7-23
收藏
得分:0 
类方法 stingbad.cpp中
#include"stringbad"   改为  #include"stringbad.h" 试试

-︻┻┳═一 ☆ 悲伤的代价就是让自己明白什么是最重要的和应该珍惜的
2007-11-28 15:57
jiangzw625
Rank: 1
等 级:新手上路
帖 子:119
专家分:0
注 册:2006-3-27
收藏
得分:0 
你用的是什么编译器,vc6有个BUG,包含<iostream>之后,你重载<< or >>时编译不通过,用<iostream.h>就没事

马马乎乎
2007-11-28 19:35
快速回复:新生的问题,弄了好不久,不能编译通过,大家看一看,在线等!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014851 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved