| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1882 人关注过本帖
标题:初学者问题,望高手指教!
只看楼主 加入收藏
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
厉害,我一直在学c#,mobile平台的
2008-05-03 20:21
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
用命名空间不一定就好..因为会有空间污染问题...如果不是后来用一个新的空间隔开,没办法通过编译..#include "stdafx.h"这个文件是c下面一个文件替代..你找找看

学习需要安静。。海盗要重新来过。。
2008-05-03 20:25
yangyangfeng
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-5-4
收藏
得分:0 
#include <iostream>
#include<string>
using namespace std;
namespace demo
{
class student  
{
    friend ostream & operator<<(ostream &,const student & );
    friend istream & operator>>(istream & ,student & );
public:
    student(int,string,string);
    student(student &);
    int getAge();
    string getName();
    string getClassName();
    void setAge(int);
    void setName(string);
    void setClassName(string);
    virtual ~student();
private:
    int age;
    string name;
    string className;
};

student::student(student &stu)
{
    this->age = stu.age;
    this->className = stu.className;
    this->name = stu.name;
}

student::student(int age,string name,string className)
{
    this->age = age;
    this->name = name;
    this->className = className;
}

int student::getAge(){
    return this->age;
}

string student::getName(){
    return this->name;
}

string student::getClassName(){
    return this->className;
}

void student::setAge(int age){
    this->age = age;
}

void student::setName(string name){
    this->name = name;
}

void student::setClassName(string className){
    this->className = className;
}
student::~student()
{
}

int main(int argc, char* argv[])
{
    return 0;
}

ostream & operator<<(ostream &out ,const student &stu){
    out<<"this student info is :\n"
        <<"name :"<<stu.name<<"\n"
        <<"age :"<<stu.age<<"\n"
        <<"className :"<<stu.className<<"\n"<<endl;
    return out;
}

istream &operator>>(istream &in ,student &stu)
{
    in>>"Please input this student info :\n";
    cout<<"name is :"<<"\n";
    in>>stu.name;
    cout<<"age is:"<<"\n";
    in>>stu.age;
    cout<<"className is:"<<"\n";
    in>>stu.className;
    return in;
}
}
2008-05-04 09:54
快速回复:初学者问题,望高手指教!
数据加载中...
 
   



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

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