| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1882 人关注过本帖
标题:初学者问题,望高手指教!
只看楼主 加入收藏
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
我用了三楼的代码,可是出现了
test.cpp(98) : fatal error C1010: unexpected end of file while looking for precompiled header directive
这样的错误这是怎么回事?
2008-05-03 19:33
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
我用vc6.0调好给你的..加个main()

学习需要安静。。海盗要重新来过。。
2008-05-03 19:35
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
对啊,我刚才也用vc6.0把你的代码复制进去调试的,可是就报上面的错误,不知道为什么,我刚学就遇到这样的麻烦,真有点郁闷
2008-05-03 19:39
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
你刚学就写这种程序,会不会夸张了一点,你知道你写得程序是什么意思吗?如果不懂,就算程序能运行也没什么意义。

i like linux...
2008-05-03 19:56
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
知道啊,不过我这种错误却解决不了,哎。。。帮帮忙吧,我有些头大了
2008-05-03 19:59
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
你真的懂吗?你看一下你的main()函数:
int main(int argc, char* argv[])
{
    return 0;
}
什么都没有,能不错吗?你若想输出学生的信息,你要调用他的函数啊。

i like linux...
2008-05-03 20:05
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分: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;
}
}
int main(void)
{
    demo::student s(14,"王二","一班");
    cout<<s;
    return 0;
}

学习需要安静。。海盗要重新来过。。
2008-05-03 20:06
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
谢谢啊,不过错了,哎。。。
2008-05-03 20:15
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
你的程序很有点c#的味道..呵呵..

学习需要安静。。海盗要重新来过。。
2008-05-03 20:16
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
恩,你给我的程序我在头部加了一个#include "stdafx.h"
就可以了,不过请问为什么要用using namespace语句?我刚才的那个#include "stdafx.h" 和#include "iostream.h"不可以吗?还有就是我本来是写在三个文件中的,student.h定义类,student.cpp实现类定义,另一个文件中定义main函数,我没有用using namespace std,我一直在用 #include "stdafx.h" 和#include "iostream.h"为什么会出错?请明示好吗?谢谢了!
2008-05-03 20:20
快速回复:初学者问题,望高手指教!
数据加载中...
 
   



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

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