视觉错误在使用 #include "DarkGDK.h" 编译程序时出现C++
visual Error coming while compiling C++ program using #include "DarkGDK.h"
我正在尝试运行c++代码,但我面临这个错误
Build started: Project: roman numerals, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:usersownerdocumentsdark gdkprojectsroman numeralsroman numeralsmain.cpp(40) : error C2065: 'number' : undeclared identifier
1>c:usersownerdocumentsdark gdkprojectsroman numeralsroman numeralsmain.cpp(40) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Build log was saved at "file://c:UsersOwnerDocumentsDark GDKProjectsroman numeralsroman numeralsDebugBuildLog.htm"
1>roman numerals - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这是代码:
#include "DarkGDK.h"
const int I = 1;
const int II = 2;
const int III = 3;
const int IV = 4;
const int V = 5;
void setup();
void input();
void display();
void cleanup();
void DarkGDK()
{
setup();
input();
cleanup();
}
void setup()
{
dbSetWindowOff();
dbLoadBitmap("C:\Users\Owners\Pictures\DeVry\roman numeral 1.bmp",I);
dbLoadBitmap("C:\Users\Owners\Pictures\DeVry\roman numeral 2.bmp",II);
dbLoadBitmap("C:\Users\Owners\Pictures\DeVry\roman numeral 3.bmp",III);
dbLoadBitmap("C:\Users\Owners\Pictures\DeVry\roamn numeral 4.bmp",IV);
dbLoadBitmap("C:\Users\Owners\Pictures\DeVry\roamn numeral 5.bmp",V);
}
void input()
{
dbPrint("enter a number1 to 5 to see its roman numeral");
int number = 0;
number = atoi(dbInput());
display();
}
void display ()
{
while (number !=6)
{
switch (number)
{
case 1:
dbCopyBitmap(I,0);
break;
case 2:
dbCopyBitmap(II,0);
break;
case 3:
dbCopyBitmap(III,0);
break;
case 4:
dbCopyBitmap(IV,0);
break;
case 5:
dbCopyBitmap(V,0);
break;
case 6:
dbPrint("ending program");
dbWait(2000);
default:
dbPrint("not a valid choice, only numbers 1 through 5 work");
dbPrint("try again");
}
}
}
void cleanup ()
{
dbDeleteImage(I);
dbDeleteImage(II);
dbDeleteImage(III);
dbDeleteImage(IV);
dbDeleteImage(V);
}
void input()
{
dbPrint("enter a number1 to 5 to see its roman numeral");
int number = 0;
number = atoi(dbInput());
display();
}
void display ()
{
while (number !=6)
{
// ...
display
函数在其作用域中没有名为number
的变量可访问。number
的作用域仅在input
函数中,不能传播到它依次调用的函数
您可能需要将number
参数传递给display
函数。
int number = 0;
number = atoi(dbInput());
- display();
+ display(number);
}
-void display ()
+void display (int number)
{
while (number !=6)
{
您在display()
函数中使用number
变量。
你在Input()函数中声明了变量'number',这意味着它只存在于这个函数中。您试图从另一个函数(在第40行)使用它,编译器看不到它。您需要做的是将number放在代码顶部的任何函数之外(const int声明所在的位置):
如
int number;
void input()
{
dbPrint("enter a number1 to 5 to see its roman numeral");
number = atoi(dbInput()); //Set the value of number here
display();
}
void display ()
{
while (number !=6) //use number here
{
...
}
}
相关文章:
- 无法在 dev-c++ 上编译程序?
- 当出现错误ld return 1退出状态时,如何编译程序
- 使用 openCV 编译程序时收集 2 ld 错误
- Gecode,使用 gecode.int.hh 编译程序时出错
- 如何创建像标准库头一样的头,以便在不链接头中函数的所有对象文件的情况下编译程序?
- 如何在前沿的Linux上编译程序以在旧Linux上运行
- 使用谷歌测试编译程序时"g++ is not a full path"
- 尝试使用生成文件编译程序时"fatal error: boost/regex.hpp: No such file or directory" C++
- g++ 在我尝试用 ONE LINE 编译程序时崩溃了
- 尝试使用Boost和Ncurses库进行编译程序时会遇到错误
- 编译程序时错误消息
- 当我尝试编译程序时,我遇到了一堆错误,例如:'std::max':找不到匹配的重载函数
- 在编译程序时遇到 C++ Visual Studio 编译器错误"htonf"
- 在VS中编译程序,无需外部运行时DLL
- 嵌入式C++解释器,用于在编译程序中操作数据
- 如何组合两个单独的生成文件来编译程序
- 编译程序提供"undefined reference"
- 嗨,我有一个编程项目,编译程序时出现奇怪的错误
- Sublime文本3-编译程序并在终端上运行
- 在Windows下编译程序会给出一堆"error: template with C linkage"报告