| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1882 人关注过本帖
标题:初学者问题,望高手指教!
取消只看楼主 加入收藏
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
 问题点数:0 回复次数:8 
初学者问题,望高手指教!
#include "stdafx.h"
#include "iostream.h"

class student  
{
    friend ostream & operator<<(ostream &,const student & );
    friend istream & operator>>(istream & ,student & );
public:
    student(student &);
    student(int,string,string);
    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;
}

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;
}
这是我的代码,为什么会报错误?
错误为:
stduentT.cpp
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(14) : error C2629: unexpected 'class student ('
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(14) : error C2238: unexpected token(s) preceding ';'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(16) : error C2146: syntax error : missing ';' before identifier 'getName'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(16) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(17) : error C2146: syntax error : missing ';' before identifier 'getClassName'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(17) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(19) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(20) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2146: syntax error : missing ';' before identifier 'name'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2501: 'name' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2146: syntax error : missing ';' before identifier 'className'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2501: 'className' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(31) : error C2039: 'className' : is not a member of 'student'
        H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(31) : error C2039: 'className' : is not a member of 'student'
        H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(32) : error C2039: 'name' : is not a member of 'student'
        H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(32) : error C2039: 'name' : is not a member of 'student'
        H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(35) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(36) : error C2511: 'student::student' : overloaded member function 'void (int)' not found in 'student'
        H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : error C2143: syntax error : missing ';' before 'tag::id'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
刚开始学习,就出这样的错误很郁闷,希望大家能帮帮小弟,谢谢!

[[it] 本帖最后由 fly_woniu 于 2008-5-3 18:35 编辑 [/it]]
搜索更多相关主题的帖子: 初学者 指教 
2008-05-03 18:31
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
能不能说清楚一些啊,我看了好长时间都没有发现问题,可以具体点吗?谢谢了!~
2008-05-03 19:11
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
头文件"iostream.h"应该可以啊?请问一下我的错误倒地处在什么地方?我想知道原因,可以指导一下吗?谢谢了啊!
2008-05-03 19:18
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
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
对啊,我刚才也用vc6.0把你的代码复制进去调试的,可是就报上面的错误,不知道为什么,我刚学就遇到这样的麻烦,真有点郁闷
2008-05-03 19:39
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
知道啊,不过我这种错误却解决不了,哎。。。帮帮忙吧,我有些头大了
2008-05-03 19:59
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
谢谢啊,不过错了,哎。。。
2008-05-03 20:15
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
fly_woniu
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-5-3
收藏
得分:0 
厉害,我一直在学c#,mobile平台的
2008-05-03 20:21
快速回复:初学者问题,望高手指教!
数据加载中...
 
   



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

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