读书人

请问一下高手有关C++的有关问题

发布时间: 2012-04-01 17:23:46 作者: rapoo

请教一下高手,有关C++的问题!
我是自学的C++,刚调试一个程序就没有调试出来!请高手指点一下!多谢啦。

但错误总是:fatal error C1083: Cannot open include file: 'sclass2_1_demo.h': No such file or directory
执行 cl.exe 时出错.

下面是程序!

#ifndef _SCLASS2_1_DEMO_H_
#define _SCLASS2_1_DEMO_H_
#include <iostream>
using namespace std;
class CDemo
{
public:
void SetI(int a)
{
i=a;
}
void SetJ(int b)
{
j=b;
}
void GetI()
{
cout <<"i="<<i<<endl;
}
void GetJ()
{
cout <<"j="<<j<<endl;
}
protected:
int j;
private:
int i;
};
#endif
#include "sclass2_1_demo.h"
void main(void)
{
CDemo d;
d.SetI(10);
d.SetJ(20);
d.GetI();
d.GetJ();
}
并且我也建了一个项目,但错误确还是如此!请各位帮助看一下!感激不尽![/i][/i][i][/i][i][/i][i][/i][/i]

[解决办法]
握爪 你的问题我还看不懂 呵呵 关于我们这些自学者 那些大学生总是瞧不起我们
[解决办法]
我QQ292089037 加我吧 一起学习
[解决办法]
首先你的项目属性是否为控制台程序,第二就是你的头文件是否为sclass2_1_demo.h
[解决办法]
只是一个主程序找不到头文件的问题,设置下头文件引入目录或改变下sclass2_1_demo.h文件的所在目录。这个问题跟你的main程序逻辑没有关系。
[解决办法]
找不到 头文件错误。
从你的意图来看你应该是将

C/C++ code
#ifndef _SCLASS2_1_DEMO_H_#define _SCLASS2_1_DEMO_H_#include <iostream>using namespace std;class CDemo{public:void SetI(int a){i=a;}void SetJ(int b){j=b;}void GetI(){cout <<"i="<<i<<endl;}void GetJ(){cout <<"j="<<j<<endl;}protected:int j;private:int i;};#endif
[解决办法]
#ifndef _SCLASS2_1_DEMO_H_
#define _SCLASS2_1_DEMO_H_
#include <iostream>
using namespace std;
class CDemo
{
public:
void SetI(int a)
{
i=a;
}
void SetJ(int b)
{
j=b;
}
void GetI()
{
cout <<"i="<<i<<endl;
}
void GetJ()
{
cout <<"j="<<j<<endl;
}
protected:
int j;
private:
int i;
};
#endif


上面这段要放在另外一个文件中,名字为sclass2_1_demo.h

读书人网 >C++

热点推荐