当前位置:编程学习 > C/C++ >>

C++中关于这个vector的一点小疑问

RT   在做课程设计  设计了一个程序  但编译时 出现了一个错误

“ Cannot open include file: 'vector.h': No such file or directory”

我记得VECTOR是C++的一个标准库啊     为什么会出现这个情况呢?

顺便说一下  我用的编译器是VC++6.0

追问:这些都吸都是我们称为的“头文件”

这些文件中包含了一些我们所需要的一些信息

例如iostream   这个头文件中  就包含了我们所需要的输入输出流   即cout cin 等等

所以  这些头文件都是当你在程序中需要时便进行添加  不需要 则不需要进行添加  当然  你添加的话也不会出什么错误的 

其次。。程序看着蛋疼   不看了。

 

答案:

像iostream,我就在乱用,什么程序开头都加,不知道是不是对的,string好像是程序语句中用到string语句的时候才加,具体的用法教我下。还有,我的D:\编程作业\PRIMER PLUS\汽车\冰箱MAIN.cpp(3) : fatal error C1083: Cannot open include file: 'icebox.h': No such file or directory
icebox.cpp
执行 cl.exe 时出错.

但是,我检查了N道icebox.h文件是对的啊,

我的主程序是

#include<iostream>
using namespace std;
#include "icebox.h"

void main()
{
 //冰箱启动flag
 int i;
 //roomtemperature,maxinnertemperature,mininnertemperature
 icebox myicebox(20,8,-8);
 cout<<"1)启动  2)升温   3)降温   4)速冻   5)停止"<<endl;  
 cin>>i;
 if(i==1)
  myicebox.start();
 if(i==2)
  myicebox.increase();
 if(i==3)
  myicebox.decrease();
 if(i==4)
  myicebox.freeze();
 if(i==5)
  myicebox.stop();
}

 

 

icebox.h是

// icebox.h: interface for the icebox class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ICEBOX_H__0D82DEF8_848D_4BA8_8634_3E22FA98AF94__INCLUDED_)
#define AFX_ICEBOX_H__0D82DEF8_848D_4BA8_8634_3E22FA98AF94__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iostream>
using namespace std;

class icebox 
{
public:
 icebox();
 icebox(int iroomtemperature,int imaxinnertemperature,int imininnertemperature);
 virtual ~icebox();

 void start();
 void decrease();
 void increase();
 void freeze();
 void stop();


private:
 int roomtemperature;
 int innertemperature;
 int maxinnertemperature;
 int mininnertemperature;
 int statu;
};

#endif // !defined(AFX_ICEBOX_H__0D82DEF8_848D_4BA8_8634_3E22FA98AF94__INCLUDED_)

 

 

icebox.cpp如下

// icebox.cpp: implementation of the icebox class.
//
//////////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;
#include "icebox.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

icebox::icebox()
{

}

icebox::~icebox()
{

}


icebox::icebox(int iroomtemperature,int imaxinnertemperature,int imininnertemperature)
{
 roomtemperature=iroomtemperature;
 maxinnertemperature=imaxinnertemperature;
 mininnertemperature=imininnertemperature;
 if(roomtemperature>maxinnertemperature)
 {
  innertemperature=maxinnertemperature;
 }
 else if(innertemperature<maxinnertemperature)
 {
  innertemperature=mininnertemperature;
 }
 else
 {
  innertemperature=roomtemperature;
 }
 statu=0;

}

void icebox::start()
{
 
 if(statu==0)
 {
  cout<<"冰箱启动,目前内部温度为"<<innertemperature<<"摄氏度,请按您的需要调整温度"<<endl;
 }
 else
 {
  cout<<"冰箱不能重复启动";
     return;
 }
}

void icebox::increase()
{
 if(statu==1)
 {
  innertemperature++;
  cout<<"冰箱升温,目前内部温度为"<<innertemperature<<"如需继续升温请按2键"<<endl;
 }
 else
 {
  cout<<"冰箱未启动,如需启动请按1键";
     return;
 }
}

void icebox::decrease()
{
 if(statu==1)
 {
  innertemperature--;
  cout<<"冰箱升温,目前内部温度为"<<innertemperature<<"如需继续降温请按3键"<<endl;
 }
 else
 {
  cout<<"冰箱未启动,如需启动请按1键";
     return;
 }
}

void icebox::freeze()
{
 if(statu==1)
 {
  innertemperature=mininnertemperature;
  cout<<"冰箱速冻,目前内部温度为"<<innertemperature<<"已达冰箱最低温度"<<endl;
 }
 else
 {
  cout<<"冰箱未启动,如需启动请按1键";
     return;
 }
}

void icebox::stop()
{
 if(statu==1)
 {
  statu=0;
  cout<<"冰箱已停止工作"<<endl;
 }
 else
 {
  cout<<"冰箱没有工作,如需启动请按1键";
     return;
 }
}
已经检测了,只有上面那个icebox.h的问题,无其它问题,请大虾指教。

标准系统头文件不推荐加 .h ,也就是写成#include<vector>试一下看看...
把#include<vector.h>
改为#include<vector>
using namespace std;
这2行

上一个:谁能帮忙做个C++程序啊 不胜感谢!
下一个:此C++程序运行的结果为何不出来?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,