| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 817 人关注过本帖
标题:这个程序是什么问题
只看楼主 加入收藏
huang1938120
Rank: 2
等 级:论坛游民
帖 子:51
专家分:41
注 册:2012-10-30
结帖率:92.86%
收藏
已结贴  问题点数:20 回复次数:9 
这个程序是什么问题
#include<string>
#include"stdafx.h"
#include<conio.h>
using namespace std;
class here
{
public:
    here(int n,string z,char s)
    {
        num=n;
        name=z;
        sex=s;
        cout<<"constructor called."<<endl;
    }
    ~here( )
    {
        cout<<"destructor called."<<endl;
    }
    void qu_num( )
    {
        cout<<num<<endl;
        cout<<name<<endl;
        cout<<sex<<endl;
    }
   
private:
    int num;
    string name;
    char sex;
};
int main( )
{
    here t(100,"huang",'f');
    t.qu_num();
    getch( );
    return 0;

}
 这是那里的错误 请指教
搜索更多相关主题的帖子: namespace private include public 
2013-04-15 16:29
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
这是想干嘛,请指教

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-04-15 16:31
zhuxiaoneng
Rank: 4
等 级:业余侠客
威 望:2
帖 子:51
专家分:215
注 册:2013-4-10
收藏
得分:0 
这个程序没有问题
 here t(100,"huang",'f'); 构造一个对象
会调用:
 here(int n,string z,char s)
    {
        num=n;
        name=z;
        sex=s;
        cout<<"constructor called."<<endl;
    }
这个函数

接着调用
 t.qu_num();
输出:
100
huang
f

getch( ); 接收一个字符,这个函数在这也可不写,作用就是让程序暂停在那儿,等着你的输入

然后程序执行完毕,调用析构函数
    ~here( )
    {
        cout<<"destructor called."<<endl;
    }
2013-04-15 16:44
huang1938120
Rank: 2
等 级:论坛游民
帖 子:51
专家分:41
注 册:2012-10-30
收藏
得分:0 
  就是输出一个人的编号 姓名 和性别 。  编号和性别这个我自己可以弄出来 但是要姓名这个字符串 我就不行了   所以想让你指教俺一下 谢谢
2013-04-15 16:46
huang1938120
Rank: 2
等 级:论坛游民
帖 子:51
专家分:41
注 册:2012-10-30
收藏
得分:0 
回复 2楼 peach5460
不行啊 运行会有错误
f:\新建文件夹\草稿107\草稿107.cpp(683) : error C2679: 二进制“<<” : 没有找到接受“<未知>”类型的右操作数的运算符(或没有可接受的转换)
2013-04-15 16:47
吴丽华
Rank: 2
来 自:湖北师范学院
等 级:论坛游民
帖 子:55
专家分:15
注 册:2012-12-31
收藏
得分:5 
#include<iostream>
#include<string>
using namespace std;
#include<conio.h>

class here
{
public:
    here(int n,string z,char s)
    {
        num=n;
        name=z;
        sex=s;
        cout<<"constructor called."<<endl;
    }
    ~here( )
    {
        cout<<"destructor called."<<endl;
    }

   
    void qu_num( )
    {
        cout<<num<<endl;
        cout<<name<<endl;
        cout<<sex<<endl;
    }
   
private:
    int num;
    string name;
    char sex;
};
int main( )
{
    here t(100,"huang",'f');
    t.qu_num();
    getch( );
   
    return 0;

}我才开始学结构体,进度比你们慢点,看了下书,把你的程序改成这个就行了,你对照下

人生如棋,落子无悔!
2013-04-15 18:06
如蜗牛
Rank: 2
等 级:论坛游民
威 望:1
帖 子:40
专家分:42
注 册:2013-4-12
收藏
得分:5 
回复 5楼 huang1938120
您没有将<iostream>的头文件包括进来吧~~~
2013-04-15 22:09
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:5 
#include <iostream>
using namespace std;
你没有头文件,所以会出错,把这个加上去,立马解决问题

Maybe
2013-04-15 23:05
zhangling199
Rank: 1
等 级:新手上路
帖 子:2
专家分:8
注 册:2013-4-11
收藏
得分:5 
VC++中没有#include"stdafx.h"
这么一个文件,你自己也没有定义这样一个文件,所以在执行的时候找不到#include"stdafx.h"这个文件!还有就是你没写#include<iostream>这个头文件!
最后输出结果是下面这样的吗?
constructor called.
100
huang
f
2013-04-15 23:07
马小柯
Rank: 2
等 级:论坛游民
帖 子:17
专家分:14
注 册:2013-4-10
收藏
得分:0 
#include<string>
 #include<conio.h>  #include"stdafx.h"去掉即可
 #include"iostream"
 using namespace std;
 class here
 {
 public:
     here(int n,string z,char s)
     {
         num=n;
         name=z;
         sex=s;
         cout<<"constructor called."<<endl;
     }
     ~here( )
     {
         cout<<"destructor called."<<endl;
     }
     void qu_num( )
     {
         cout<<num<<endl;
         cout<<name<<endl;
         cout<<sex<<endl;
    }
     
private:
    int num;
     string name;
     char sex;
 };
 int main( )
 {
     here t(100,"huang",'f');
     t.qu_num();
     getch( );
     return 0;
 
}
2013-04-18 17:58
快速回复:这个程序是什么问题
数据加载中...
 
   



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

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