找出错误原因
class point{
int x,y;
public:
point(int vx,int vy){x = vx; y = vy;}
int getx(){return x;}
int gety(){return y;}
};
class str{
int length;
char *contents;
public:
str(char *s)
{
length = strlen(s);
contents = new char[length + 1];
strcpy(contents,s);
}
void show(int x,int y)
{
goto(x,y);//提示[C++ Error] Unit1.cpp(29): E2271 Goto statement missing label
printf( "%s\n ",contents);
}
};
class outer_class{
point p1;
str s1;
public:
outer_class(int x,int y,char *s);
void show()
{s1.show(p1.getx(),p1.gety()); }
};
outer_class::outer_class(int x,int y,char *s):p1(x,y),s1(s)
{}
int main(int argc, char* argv[])
{
char *s = "the string object ";
outer_class object(230,100,s);
object.show();
cin.get();
请问是怎么回事??以前很少用goto,所以想请高手指点.谢谢
[解决办法]
goto 是关键字, 不是函数
[解决办法]
使用gotoxy()
Header File
conio.h
Category
Console I/O Routines
Prototype
void gotoxy(int x, int y);
Description
Positions cursor in text window.
gotoxy moves the cursor to the given position in the current text window. If the coordinates are in any way invalid the call to gotoxy is ignored. An example of this is a call to gotoxy(40,30) when (35,25) is the bottom right position in the window. Neither argument to gotoxy can be zero.
Note:Do not use this function in Win32 GUI applications.
Return Value
None.