头文件包含问题!头文件包含不进去啊!!!!急!!!!

xinghun129 2009-05-08 08:51:16
头文件包含不进去啊!!!!
急!!!!
帮帮忙!

#ifndef EX1_H
#define EX1_H


class EX1 {

private:
int N;
vector <double> num;
double mean,variance,stddeviation;
public:

void shuru();
void qmean();
void qvariance();
void qstddeviation();
void show();
};

#endif//EX1_H///:~

#include<iostream>
#include<vector>
#include<cmath>
#include<ex1.h>


using namespace std;


void EX1::shuru()
{
cout << "请输入您要输入数据的个数:" ;
cin >> N;
for(int i = 1;i <= N;i++){

cout << "请输入第" << i << "个数" << endl;
cin >> num.push_back([i-1]) >> endl;
}
}

void EX1::qmean()
{

for(int i = 0;i < N;i++){

mean = mean + num[i];
}
mean = mean/N;
}

void EX1::qvariance()
{

float x = 0;
for(int i = 0;i < N;i++){

x = x + (num[i] - mean)*(num[i] - mean);
}
variance = x/(N - 1);
}

void EX1::qstddeviation()
{

stddeviation = (sqrt)variance;
}

void EX1::show()
{

cout << "平均值:" << mean << endl;
cout << "方差:" << variance << endl;
cout << "标准差:" << stddeviation << endl;
}


错误信息:
C:\Users\xinghun\Desktop\作业\1>g++ -c ex1.cpp
ex.cpp:4:15: ex1.h: No such file or directory
...全文
600 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
amossavez 2009-05-08
  • 打赏
  • 举报
回复
楼主呀,除了要把<>改成""之外,你的代码里有好多错误呀,自己好好改改吧!!

#include<iostream>
#include<vector>
#include<cmath>
#include<ex1.h>


using namespace std;


void EX1::shuru()
{
cout << "请输入您要输入数据的个数:" ;
cin >> N;
for(int i = 1;i <= N;i++){

cout << "请输入第" << i << "个数" << endl;
cin >> num.push_back([i-1]) >> endl; //你的num是空的你怎么输出呀??你[]什么意思?你先看看vector的用法吧,全错了!!!
}
}

void EX1::qmean()
{

for(int i = 0;i < N;i++){

mean = mean + num[i];
}
mean = mean/N;
}

void EX1::qvariance()
{

float x = 0;
for(int i = 0;i < N;i++){

x = x + (num[i] - mean)*(num[i] - mean);
}
variance = x/(N - 1);
}

void EX1::qstddeviation()
{

stddeviation = (sqrt)variance; //这个地方也有错!!
}

void EX1::show()
{

cout << "平均值:" << mean << endl;
cout << "方差:" << variance << endl;
cout << "标准差:" << stddeviation << endl;
}


xinghun129 2009-05-08
  • 打赏
  • 举报
回复
可以了 谢谢
lingyin55 2009-05-08
  • 打赏
  • 举报
回复
不好意思,没注意,你可以在头文件的vector前加std::
或者把
#include<iostream>
#include<vector>
#include<cmath>
#include<ex1.h>


using namespace std;

这整段都加到头文件中

[Quote=引用 7 楼 xinghun129 的回复:]
刚按照你说的做了,可是还是出现了同样的问题啊
[/Quote]
xinghun129 2009-05-08
  • 打赏
  • 举报
回复
刚按照你说的做了,可是还是出现了同样的问题啊
lingyin55 2009-05-08
  • 打赏
  • 举报
回复
#include<vector>
#include<cmath>

这两个写到头文件中去

[Quote=引用 5 楼 xinghun129 的回复:]
改成引号之后出现了以下错误:

C:\Users\xinghun\Desktop\11>g++ -c ex1.cpp
In file included from ex1.cpp:4:
ex1.h:9: error: ISO C++ forbids declaration of `vector' with no type
ex1.h:9: error: expected `;' before ' <' token
ex1.cpp: In member function `void EX1::shuru()':
ex1.cpp:17: error: `num' was not declared in this scope
ex1.cpp:17: error: expected primary-expression before '[…
[/Quote]
xinghun129 2009-05-08
  • 打赏
  • 举报
回复
改成引号之后出现了以下错误:

C:\Users\xinghun\Desktop\11>g++ -c ex1.cpp
In file included from ex1.cpp:4:
ex1.h:9: error: ISO C++ forbids declaration of `vector' with no type
ex1.h:9: error: expected `;' before '<' token
ex1.cpp: In member function `void EX1::shuru()':
ex1.cpp:17: error: `num' was not declared in this scope
ex1.cpp:17: error: expected primary-expression before '[' token
ex1.cpp: In member function `void EX1::qmean()':
ex1.cpp:26: error: `num' was not declared in this scope
ex1.cpp: In member function `void EX1::qvariance()':
ex1.cpp:37: error: `num' was not declared in this scope
ex1.cpp: In member function `void EX1::qstddeviation()':
ex1.cpp:45: error: cannot resolve overloaded function `sqrt' based on conversion
to type `double'
ex1.cpp:45: error: expected `;' before "variance"

C:\Users\xinghun\Desktop\11>
lingyin55 2009-05-08
  • 打赏
  • 举报
回复
建议:
使用系统里提供的头文件时使用尖括号
使用自己编写的头文件时使用双引号
xinghun129 2009-05-08
  • 打赏
  • 举报
回复
刚才试了,还是不行啊。还是一样的错误
lingyin55 2009-05-08
  • 打赏
  • 举报
回复
#include "ex1.h"
crst_zh 2009-05-08
  • 打赏
  • 举报
回复
#include“ex1.h”

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧