我可以: 邀请好友来看>>
ZOL星空(中国) > 技术星空(中国) > C/C++星空(中国) > 小弟初学c++,对于其中的错误百思不得其解,请高手赐教
帖子很冷清,卤煮很失落!求安慰
返回列表
签到
手机签到经验翻倍!
快来扫一扫!

小弟初学c++,对于其中的错误百思不得其解,请高手赐教

656浏览 / 8回复

08fish80

08fish80

0
精华
2
帖子

等  级:Lv.1
经  验:23
  • Z金豆: 0

    千万礼品等你来兑哦~快点击这里兑换吧~

  • 城  市:四川
  • 注  册:2010-08-11
  • 登  录:2010-08-11
发表于 2010-08-11 22:11:17
电梯直达 确定
楼主
/****************
****node.h*******
****************/
#include
using namespace std;
class node
{
    friend class linklist;
    friend void shownode(node &n);
public:
    node();
    node(node &n);
    node(int i,char c='0');
    node(int i,char c,node *p,node *n);
    int readi() const;
    char readc() const;
    node * readp() const;
    node * readn() const;
    bool set(int i);
    bool set(char c);
    bool setp(node *p);
    bool setn(node *n);
    ~node();
    static int allocetion();
private:
    int idata;
    char cdata;
    node *prior;
    node *next;
    static int count;
};
/*****************
***node.cpp*******
*****************/
#include"node.h"
#include
using namespce std;
int node::count=0
int node::readi() const
{
    return idata;
}
char node::readc() const
{
    return cdata;
}
node *node::readp() const
{
    return prior;
}
node *node::readn() const
{
    return next;
}
bool node::set(char c)
{
    cdata=c;
    return true;
}
bool node::set(int i)
{
    idata=i;
    return true;
}
bool node::setp(node *p)
{
    prior=p;
    return true;
}
bool node::setn(node *n)
{
    next=n;
    return true;
}
node::node()
{
    cout<<"node constructor is runing..."<    idata=0;
    cdata='0';
    prior=NULL;
    next=NULL;
    count++;
}
node::node(int i,char c)
{
    cout<<"node constructor is runing..."<    idata=i;
    cdata=c;
    prior=NULL;
    next=NULL;
    count++;
}
node::node(int i,char c,node *p,node *n)
{
    cout<<"node constructor is runing..."<    idata=i;
    cdata=c;
    prior=p;
    next=n;
    count++;
}
node::node(node &n)
{
    count++;
    idata=n.idata;
    cdata=n.cdata;
    prior=n.prior;
    next=n.next;
}
node::~node()
{
    cout--;
    cout<<"node destructor is running..."<}
int node allocetion()
{
    return count;
}
void shownode(node &n)
{
    cout<<"n.idata"<<'t'<}
/***************
****linklist.h**
***************/
#include"node.h"
#include
using namespace std;
class linklist
{
public:
    linklist(int i,char c);
    linklist(linklist &l);
    ~linklist();
    bool locate(int i);
    bool locate(char c);
    bool insert(int i=0,char c='0');
    bool Delete();
    void show();
    void Destroy();
private:
    node head;
    node * pcurrent;
};
linklist::linklist(int i,char c):head(i,c)
{
    cout<<"linklist constructor is runing..."<    pcurrent=&head
}
linklist::linklist(linklist &l):head(l.head)
{
    cout<<"linklist deep cloner running..."<    pcurrent=&head
    node * ptemp1=l.head.next;
    while(ptemp1!=NULL)
    {
        node * ptemp2=new node(ptemp1->idata,ptemp1->cdata,pcurrent,NULL);
        pcurrent->next=ptemp2;
        pcurrent=pcurrent->next;
        ptemp1=ptemp1->next ;
    }
}
linklist::~linklist()
{
    cout<<"linklist destructor is running..."<    Destroy();
}
bool linklist::locate(int i)
{
    node *ptemp=&head
    while(ptemp!=NULL)
    {
        if(ptemp->readi()==i)
        {
            pcurrent=ptemp;
            return true;
        }
        ptemp=ptemp->readn();
    }
    return false;
}
bool linklist::locate(char c)
{
    node *ptemp=&head
    while(ptemp!=NULL)
    {
        if(ptemp->readc()=='c')
        {
            pcurrent=ptemp;
            return true;
        }
        ptemp=ptemp->readn();
    }
    return false;
}
bool linklist::insert(int i,char c)
{
    if(pcurrent!=NULL)
    {
        node * temp=new node(i,c,pcurrent,pcurrent->readn());
        if(pcurrent->readn()!=NULL)
        {
            pcurrent->readn()->setp(temp);
        }
        pcurrent->setn(temp);
        return true;
    }
    else
    {
        return false;
    }
}
bool linklist::Delete()
{
    if(pcurrent!=NULL&&pcurrent!=&head)
    {
        node * temp=pcurrent;
        if(temp->readn()!=NULL)
        {
            temp->readn()->setp(pcurrent->readp());
        }
        temp->readp()->setn(pcurrent->readn());
        pcurrent=temp->readp();
        delete temp;
        return true;
    }
    else
    {
        return false;
    }
}
void linklist::show()
{
    node * ptemp=&head
    while(ptemp!=NULL)
    {
        cout<readi()<<'t'<readc()<        ptemp=ptemp->readn();
    }
}
void linklist::Destroy()
{
    node * ptemp1=head.readn();
    while (ptemp1!=NULL)
    {
        node * ptemp2=ptemp1->readn();
        delete ptemp1;
        ptemp1=ptemp2;
    }
    head.setn(NULL);
}
/******************
*****main.cpp******
******************/
#include "stdafx.h"
#include
#include"linklist.h"
using namespace std;
int main()
{
    int tempi;
    char tempc;
    cout<<"请输入一个整数和字符"<    cin>>tempi>>tempc;
    linklist a(tempi,tempc);
    a.locate(tempi);
    a.insert(1,'c');
    a.insert(2,'b');
    cout<<"after insert"<    a.show();
    node b(4,'f');
    cout<<"an independent node created"<    cout<<"use friend function to show node"<    shownode(b);
    return 0;
}

//但是程序却说
c:program filesmicotsoft visul studiomy projiectsmainnode.cpp(89);fatal error c1010:unexpected end of file while looking for precompiled header directive
执行 c1.exe时出错。
main.exe-1 error(s),0 warning(s)

小弟初学c++,对于其中的错误百思不得其解,请高手赐教

08fish80

08fish80


精华

帖子

等  级:Lv.1
经  验:23
发表于 2010-08-11 22:14:46 1楼
#include中的怎么在帖子中没有了?

08fish80

08fish80


精华

帖子

等  级:Lv.1
经  验:23
发表于 2010-08-11 22:15:31 2楼
iostream表示不出来?

08fish80

08fish80


精华

帖子

等  级:Lv.1
经  验:23
发表于 2010-08-11 22:24:32 3楼
程序中的endl;也不见了?

ayen01

ayen01


精华

帖子

等  级:Lv.1
经  验:47
发表于 2010-08-23 10:27:31 4楼
#include后面的引用呢?

蝴蝶无翼

蝴蝶无翼


精华

帖子

等  级:Lv.6
经  验:8924
发表于 2010-08-30 09:53:09 5楼
支持下楼主

lucktty

lucktty


精华

帖子

等  级:Lv.1
经  验:36
发表于 2010-09-10 08:35:26 6楼
楼主蛮厉害的 程序这么长哦


精华

帖子

等  级:Lv.1
经  验:4
发表于 2010-09-19 21:41:24 7楼

您的内容正在火速审核中,请稍等

z449349392

z449349392


精华

帖子

等  级:Lv.3
经  验:825
发表于 2010-09-22 08:57:03 8楼
include后面忘加了iosterom(输入输出流定义)

zol_wt

zol_wt


精华

帖子

等  级:Lv.12
经  验:820218
发表于 2010-09-30 22:29:29 9楼
学习

k448230290

k448230290


精华

帖子

等  级:Lv.1
经  验:16
发表于 2010-10-07 10:02:11 10楼

您的内容正在火速审核中,请稍等

高级模式
星空(中国)精选大家都在看24小时热帖7天热帖大家都在问最新回答

针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员查看帮助  或  给我提意见

快捷回复 APP下载 返回列表