| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 631 人关注过本帖
标题:大侠们帮帮忙!!实在找不出啥错?
只看楼主 加入收藏
kongwei254
Rank: 1
等 级:等待验证会员
帖 子:38
专家分:0
注 册:2008-5-18
收藏
 问题点数:0 回复次数:7 
大侠们帮帮忙!!实在找不出啥错?
//////
#include <iostream>
#ifndef STRNGBAD_H
#define STRNGBAD_H
#include "stringbad1.h"
using namespace std;
class stringbad
{
private:
    char *str;
    int len;
    static int num_strings;
public:
    
    stringbad(const char *s);
    stringbad();
    ~stringbad();
//friend function
    friend ostream & operator<<(ostream &os,const stringbad &st);
};
#endif

////////////////////////////////////////////////////
#include <iostream>
#include <cstring>
#include "stringbad1.h"
using namespace std;
int stringbad::num_strings=0;
stringbad::stringbad(const char *s)
{
    len=strlen(s);
    str=new char[len+1];
    strcpy(str,s);
    num_strings++;
    cout<<num_strings<<":\""<<str<<"\"object created\n";
}
stringbad::stringbad()
{
    len=4;
    str=new char[4];
    strcpy(str,"c++");
    num_strings++;
    cout<<num_strings<<":\""<<str<<"\"default object created\n";
}
stringbad::~stringbad()
{
    cout<<num_strings<<":\""<<str<<"\"object deleted\n";
    num_strings--;
    cout<<num_strings<<"left\n";
    delete [] str;
}
ostream & operator<<(ostream &os,const stringbad &st)
{
    os<<st.str;
    return os;
}

/////////////////////////////////////////////////////////////

#include <iostream>
#include "stringbad1.h"
using namespace std;
void callme1(stringbad &);
void callme2(stringbad);
int main()
{
    stringbad headline1("welcome to here!");
    stringbad headline2("shan dong jinan");
    stringbad sports("here is my home");
    cout<<"headline1:"<<headline1<<endl;
    cout<<"headline2:"<<headline2<<endl;
    cout<<"sports:"<<sports<<endl;
    callme1(headline1);
    cout<<"headline1:"<<headline1<<endl;
    callme2(headline2);
    cout<<"headline2:"<<headline2<<endl;
    cout<<"Initialize one object to another:\n";
    stringbad sailor=sports;
    cout<<"sailor:"<<sailor<<endl;
    cout<<"Assign one object to another:\n";
    stringbad knot;
    knot=headline1;
    cout<<"knot:"<<knot<<endl;
    cout<<"end of main()\n";
    return 0;
}
void callme1(stringbad &rsb)
{
    cout<<"string passed by reference:\n";
    cout<<"\""<<rsb<<"\"\n";
}
void callme2(stringbad sb)
{
    cout<<"string passed by value:\n";
    cout<<"\""<<sb<<"\"\n";
}
搜索更多相关主题的帖子: 大侠 
2008-05-19 21:31
Msist
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-5-20
收藏
得分:0 
新手莫怪
#include <iostream>
#include "stringbad1.h"// stringbadl.h是什么东东?
貌似没有这样的头文件
2008-05-20 12:26
newyj
Rank: 2
等 级:新手上路
威 望:3
帖 子:542
专家分:0
注 册:2008-1-4
收藏
得分:0 
"stringbad1.h"
是自己定义的头文件
2008-05-20 13:52
lixingstone
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-11-4
收藏
得分:0 
啥错啊。
2008-05-20 15:55
bibingyan
Rank: 1
来 自:湖南长沙
等 级:新手上路
帖 子:123
专家分:0
注 册:2008-3-16
收藏
得分:0 
你还是把你那个自己定义的"stringbad1.h"贴出来看看吧。

不嫌恶地狱,不迷恋人间,不羡慕天堂。
2008-05-26 23:30
kongwei254
Rank: 1
等 级:等待验证会员
帖 子:38
专家分:0
注 册:2008-5-18
收藏
得分:0 
已经解决了谢谢
2008-05-29 15:17
笨小孩6
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-3-3
收藏
得分:0 
解决了为什么不说出问题所在?楼主不厚道,只知索取,不知奉献!

最大的电子书下载基地
/in.asp?id=bxhsix
2008-05-29 21:22
kongwei254
Rank: 1
等 级:等待验证会员
帖 子:38
专家分:0
注 册:2008-5-18
收藏
得分:0 
不好意思,这个只是C++编译器的原因!!
2008-06-19 08:04
快速回复:大侠们帮帮忙!!实在找不出啥错?
数据加载中...
 
   



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

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