作业帮 > 综合 > 作业

麻烦大家帮忙看看这个C++程序

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/03/29 19:36:59
麻烦大家帮忙看看这个C++程序
#include
#include
#include
#include "rect.h"
#include "ezwin.h"
using namespace std;
int ApiMain() {
enum color {Red,Green,Blue,Yellow,Cyan,Magenta};
SimpleWindow W("Builings",10,10);
ifstream fin("data.txt");
float Width=0;
float High=0;
float XCentre=0;
float YCentre=0;
color Color=Red;
W.Open();
RectangleShape Build1(W,fin>>XCentre,fin>>YCentre,Red,fin>>Width,fin>>High);
RectangleShape Build2(W,fin>>XCentre,fin>>YCentre,Green,fin>>Width,fin>>High);
RectangleShape Build3(W,fin>>XCentre,fin>>YCentre,Blue,fin>>Width,fin>>High);
RectangleShape Build4(W,fin>>XCentre,fin>>YCentre,Magenta,fin>>Width,fin>>High);
RectangleShape Build5(W,fin>>XCentre,fin>>YCentre,Yellow,fin>>Width,fin>>High);
Build1.Draw();
Build2.Draw();
Build3.Draw();
Build4.Draw();
Build5.Draw();
return 0;
}
编译出错,系统提示:
--------------------Configuration:p337 - Win32 Debug--------------------
Compiling...
p337.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\p337\p337.cpp(17) :error C2664:'__thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,const enum color &,float,float)' :cannot convert parameter 2 from 'class std::basic_ist
ream' to 'float'
No user-defined-conversion operator available that can perform this conversion,or the operator cannot be called
C:\Program Files\Microsoft Visual Studio\MyProjects\p337\p337.cpp(18) :error C2664:'__thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,const enum color &,float,float)' :cannot convert parameter 2 from 'class std::basic_ist
ream' to 'float'
No user-defined-conversion operator available that can perform this conversion,or the operator cannot be called
C:\Program Files\Microsoft Visual Studio\MyProjects\p337\p337.cpp(19) :error C2664:'__thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,const enum color &,float,float)' :cannot convert parameter 2 from 'class std::basic_ist
ream' to 'float'
No user-defined-conversion operator available that can perform this conversion,or the operator cannot be called
C:\Program Files\Microsoft Visual Studio\MyProjects\p337\p337.cpp(20) :error C2664:'__thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,const enum color &,float,float)' :cannot convert parameter 2 from 'class std::basic_ist
ream' to 'float'
No user-defined-conversion operator available that can perform this conversion,or the operator cannot be called
请问是什么问题该怎么解决?
还有一个问题是:枚举类型的数据要想从文件直接输入到变量应该用什么语句?(直接用fin>>Color,Color是枚举类型,不能编译)
先来回答你枚举类型怎么输入的问题,其实枚举类型就是用一组标志符替换了一串数字,例如
enum enWindowClass
{
enWC_WINDOW = 0,
enWC_STATIC,
enWC_BUTTON,
enWC_VIEW,
enWC_EDIT,
enWC_LISTBOX,
enWC_LISTCTRL,
enWC_SCROLLBAR,
enWC_SLIDERCTRL,
enWC_DIALOG,
};
其中enWC_WINDOW = 0,后面的依次加一.你应该设一个int变量,输入到这个变量里,在与枚举类型的值比较即可
编译的问题,错误也十分明显,你把fin>>XCentre,fin>>YCentre,Red,fin>>Width,fin>>Heigh这样的输入操作放在RectangleShape的参数的位置是不对的,因为fin>>XCentre的类型不是float类型,应该先由文件输入,再调用RectangleShape.例如
fin>>XCentre;
fin>>YCentre,Red;
fin>>Width;
fin>>Heigh;
RectangleShape Build1(W,XCentre,YCentre,Red,Width,Heigh);
后面的几个你对照上面一句改就好了,问题就这么简单
最后问一句,你用的什么编译工具,看语法,不像是M$的
鉴于你曾出现的问题,我给你把使用EzWindows应注意的问题说一下,这也是使用任何第三方库应注意的,以VC6.0为例.
1、在"工具"->"选项"->"目录"中添加ExWindows的包含文件路径("\C++ProgramDesign\ezwin\include"),库文件路径("\C++ProgramDesign\ezwin\lib")和源文件路径("\C++ProgramDesign\ezwin\"),有些库不带源文件,可以不设置.
2、在"工程"->"设置"->"连接"->"对象/库模块"中添加使用到的第三方lib文件,在EzWindows中就是"Ezwinvc50.lib".当然,在代码中加入#pragma comment(lib,"Ezwinvc50.lib")这一句,作用是一样的.
3、参考第三方库的帮助文件,确保自己没有把库的用法搞错.
最后也是最重要的问题,为什么你的窗口显示不出来?
我看了EzWindows自带的例子,最后得出结论是全局变量与局部变量的问题,把SimpleWindow W("Builings",10,10);拿到int ApiMain(){}就OK了.