首页 新闻 会员 周边 捐助

VC++6.0中出现以下问题std' : is not a class or namespace name

0
[已解决问题] 解决于 2011-06-07 15:10

程序的目的是统计学生的平均成绩,头文件student_info.h中声明了相应的结构体和函数,问题是.h文件中都包含了#include <iostream>,为什么在相应的源文件中还会出现“ std:is not a class or namespace name”这样的错误。

以下是头文件:student_info.h

#ifdef GUARD_Student_info
#define GUARD_Student_info
#include
<iostream>
#include
<string>
#include
<vector>

struct student_info
{
string name;
double midterm,final;
std::vector
<double> homework;
};

bool compare(const student_info&, const student_info& );
std::istream
& read(std::istream&, student_info&);
std::istream
& read(std::istream&, std::vector<double>&);

#endif

以下是源文件“student_info.cpp”

#include "Student_info.h"

using namespace std;

bool compare(const student_info& x, const student_info& y)
{

return x.name<y.name;
}

istream
& read(istream& is , student_info& s)
{
is>>s.name>>s.midterm>>s.final;
read_hw(
is,s.homework);
return is;
}

istream
& read_hw(istream& in, vector<double>& hw)
{
if(in) {
hw.clear();

double x;
while(in >> x)
hw.push_back(x);

in.clear();
}
return in;
}

此外编译完后出现了30个错误,如下:

G:\project\StudentResult\student_info.cpp(4) : error C2871: 'std' : does not exist or is not a namespace
G:\project\StudentResult\student_info.cpp(6) : error C2143: syntax error : missing ',' before '&'
G:\project\StudentResult\student_info.cpp(6) : error C2059: syntax error : '&'
G:\project\StudentResult\student_info.cpp(9) : error C2065: 'x' : undeclared identifier
G:\project\StudentResult\student_info.cpp(9) : error C2228: left of '.name' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(9) : error C2065: 'y' : undeclared identifier
G:\project\StudentResult\student_info.cpp(9) : error C2228: left of '.name' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(12) : error C2143: syntax error : missing ';' before '&'
G:\project\StudentResult\student_info.cpp(12) : error C2501: 'istream' : missing storage-class or type specifiers
G:\project\StudentResult\student_info.cpp(12) : error C2061: syntax error : identifier 'istream'
G:\project\StudentResult\student_info.cpp(13) : error C2501: 'read' : missing storage-class or type specifiers
G:\project\StudentResult\student_info.cpp(14) : error C2065: 'is' : undeclared identifier
G:\project\StudentResult\student_info.cpp(14) : error C2065: 's' : undeclared identifier
G:\project\StudentResult\student_info.cpp(14) : error C2228: left of '.name' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(14) : error C2228: left of '.midterm' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(14) : error C2228: left of '.final' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(15) : error C2065: 'read_hw' : undeclared identifier
G:\project\StudentResult\student_info.cpp(15) : error C2228: left of '.homework' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(19) : error C2143: syntax error : missing ';' before '&'
G:\project\StudentResult\student_info.cpp(19) : error C2501: 'istream' : missing storage-class or type specifiers
G:\project\StudentResult\student_info.cpp(19) : error C2086: 'istream' : redefinition
G:\project\StudentResult\student_info.cpp(19) : error C2061: syntax error : identifier 'istream'
G:\project\StudentResult\student_info.cpp(20) : error C2501: 'read_hw' : missing storage-class or type specifiers
G:\project\StudentResult\student_info.cpp(20) : error C2373: 'read_hw' : redefinition; different type modifiers
G:\project\StudentResult\student_info.cpp(21) : error C2065: 'in' : undeclared identifier
G:\project\StudentResult\student_info.cpp(22) : error C2065: 'hw' : undeclared identifier
G:\project\StudentResult\student_info.cpp(22) : error C2228: left of '.clear' must have class/struct/union type
G:\project\StudentResult\student_info.cpp(25) : error C2296: '>>' : illegal, left operand has type 'double'
G:\project\StudentResult\student_info.cpp(25) : error C2297: '>>' : illegal, right operand has type 'double'
G:\project\StudentResult\student_info.cpp(25) : fatal error C1903: unable to recover from previous error(s); stopping compilation

问题补充:

当我在源文件中加入"include<iostream>"后'std' : does not exist or is not a namespace的问题就解决了,可我还是不懂,请高人指点,谢谢!

慕容小北的主页 慕容小北 | 初学一级 | 园豆:190
提问于:2011-06-06 13:47
< >
分享
最佳答案
0

这个#ifdef GUARD_Student_info,改成 #ifndef或 #pragma once

2012 | 高人七级 |园豆:21645 | 2011-06-07 14:51
嗯,这是我粗心忘写n了。昨天已经改过了,谢谢你的细心!问题也已经解决了,只要在头文件中加上using namespace std; 再编译就没有错误了。因为student_info 中用到了std,而我只包含了<iostream>,没有加命名空间,所以头文件就有错误,源文件当然编译不过。
慕容小北 | 园豆:190 (初学一级) | 2011-06-07 15:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册