退出一个函数() [英] exit a function()

查看:78
本文介绍了退出一个函数()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我正在使用VS 2008 Express C ++。

我在1999年创建了一个控制台应用程序,并在
中为VC ++ 6.0更新了它/>
2001.

我已经在上个月再次更新,并且发现了足够的差异,我现在需要使用不同的退出例程。

2001年,我可以使用do {}进行基本转义(ch!= 27);

现在显然不起作用。

那么,如何使用C ++ 2008 express退出函数?


我的一般形式是:


---- -------------------------------------------------- ------------

#include" stdafx.h"

#include< iostream>

#include< cmath>

#include< xutility>

#include< stdlib.h>

#include< cctype>

#include< conio.h>

#define PI 3.1415926535898

int n;

int ParA,ParB,ParC,ParD,ParE;


使用命名空间std;


int functionA(int& ParA,int& ParB,int& ParC,int& ParD)

// ParA到ParE是我的职能范围内的参数/变量(请原谅我,如果我/ b $ b //错误地陈述了这些条款)。

{

二级菜单解释如何使用此功能-A。

do

{

core这个函数的代码。

} while(ch_n!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}

int functionB(int& ParA,int& ; ParB,int& ParC,int& ParD,int& ParE);


二级菜单解释如何使用此功能-B。

do

{

此功能的核心代码。

} while(ch_(n + 1)!= 27);

//ch_(n + 1)是我用来逃避的字符下标。


//返回n; //其中n是核心代码中的等式。


exit(0); //这不能退出我的功能。

}

int functionC(int& ParA,int& ParB);


二级菜单解释如何使用此功能-C。

do

{

此功能的核心代码。

} while(ch_(n + 2)!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}


int main()

{



{

主要欢迎菜单,提供访问我的功能的选项,

或退出该计划。


Switch(ch)

{

case''1'':functionA (ParA,ParB,ParC,ParD);

休息;

案例''2'':functionB(ParA,ParB,ParC,ParD,ParE);

休息;

案例''3'':functionC(ParA,ParB);

休息;

默认:退出(0);

}

} while(ch!= 27);

}

解决方案

" SteveDB1" < St ****** @ discuss.microsoft.com写信息

新闻:8C ********************** ************ @ microsof t.com ...


大家好。

我''使用VS 2008 Express C ++。

我在1999年创建了一个控制台应用程序,并在2001年的b / b
中更新了VC ++ 6.0

。 br />
我已经在上个月再次更新,并且发现了足够的差异

我现在需要使用不同的退出例程。
2001年,我可以使用带有do {}的基本转义(ch!= 27);

现在显然不起作用。

那么,如何使用C ++ 2008 express退出函数?


我的一般形式是:


----- -------------------------------------------------- -----------

#include" stdafx.h"

#include< iostream>

# include< cmath>

#include< xutility>

#include< stdlib.h >

#include< cctype>

#include< conio.h>

#define PI 3.1415926535898


int n;

int ParA,ParB,ParC,ParD,ParE;


使用命名空间std;


int functionA(int& ParA,int& ParB,int& ParC,int& ParD)

// ParA到ParE是我的职能范围内的参数/变量(请原谅我,如果我/ b $ b //错误地陈述了这些条款)。

{

二级菜单解释如何使用此功能-A。

do

{

core这个函数的代码。

} while(ch_n!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}

int functionB(int& ParA,int& ; ParB,int& ParC,int& ParD,int& ParE);


二级菜单解释如何使用此功能-B。

do

{

此功能的核心代码。

} while(ch_(n + 1)!= 27);

//ch_(n + 1)是我用来逃避的字符下标。


//返回n; //其中n是核心代码中的等式。


exit(0); //这不能退出我的功能。

}

int functionC(int& ParA,int& ParB);


二级菜单解释如何使用此功能-C。

do

{

此功能的核心代码。

} while(ch_(n + 2)!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}


int main()

{



{

主要欢迎菜单,提供访问我的功能的选项,

或退出该计划。


Switch(ch)

{

case''1'':functionA (ParA,ParB,ParC,ParD);

休息;

案例''2'':functionB(ParA,ParB,ParC,ParD,ParE);

休息;

案例''3'':functionC(ParA,ParB);

休息;

默认:退出(0);

}

} while(ch!= 27);

}



exit()用于终止应用程序,而不是退出函数。

要退出函数,请使用return。


Mark


-

Mark Salsbery

Microsoft MVP - Visual C ++


中号方舟,

感谢您的回复。

我已将exit()替换为return 0;

I仍然有基本相同的问题 - 它不允许我退出

函数。

我可以用0退出程序,但没有任何键的按键允许我

退出该函数,如果我想退出,我必须关闭程序

点击cmd控制台窗口顶部的关闭''x'' 。

我想我的第一个问题是返回0问题后,我会更好

关闭而不使用do-while因为转义键不再允许我

一次出来吗?

再次,谢谢你的帮助。


" Mark Salsbery [MVP]"写道:


" SteveDB1" < St ****** @ discuss.microsoft.com写信息

新闻:8C ********************** ************ @ microsof t.com ...


大家好。

我''使用VS 2008 Express C ++。

我在1999年创建了一个控制台应用程序,并在2001年的b / b
中更新了VC ++ 6.0

。 br />
我已经在上个月再次更新,并且发现了足够的差异

我现在需要使用不同的退出例程。
2001年,我可以使用带有do {}的基本转义(ch!= 27);

现在显然不起作用。

那么,如何使用C ++ 2008 express退出函数?


我的一般形式是:


----- -------------------------------------------------- -----------

#include" stdafx.h"

#include< iostream>

#包括< cmath>

#include< xutility>

#包括< stdlib.h>

#include< cctype>

#include< conio.h>

#define PI 3.1415926535898


int n;

int ParA,ParB,ParC,ParD,ParE;


using namespace std;


int functionA(int& ParA,int& ParB,int& ParC,int& ParD)

// ParA到ParE是我的职能范围内的参数/变量(请原谅我,如果我/ b $ b //错误地陈述了这些条款)。

{

二级菜单解释如何使用此功能-A。

do

{

core这个函数的代码。

} while(ch_n!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}

int functionB(int& ParA,int& ; ParB,int& ParC,int& ParD,int& ParE);


二级菜单解释如何使用此功能-B。

do

{

此功能的核心代码。

} while(ch_(n + 1)!= 27);

//ch_(n + 1)是我用来逃避的字符下标。


//返回n; //其中n是核心代码中的等式。


exit(0); //这不能退出我的功能。

}

int functionC(int& ParA,int& ParB);


二级菜单解释如何使用此功能-C。

do

{

此功能的核心代码。

} while(ch_(n + 2)!= 27);

//返回n; //其中n是核心代码中的等式。

退出(0);

}


int main()

{



{

主要欢迎菜单,提供访问我的功能的选项,

或退出该计划。


Switch(ch)

{

case''1'':functionA (ParA,ParB,ParC,ParD);

休息;

案例''2'':functionB(ParA,ParB,ParC,ParD,ParE);

休息;

案例''3'':functionC(ParA,ParB);

休息;

默认:退出(0);

}

} while(ch!= 27);

}




exit()用于终止应用程序,而不是退出函数。

要退出函数,请使用return。


Mark


-

Mark Salsbery

Microsoft MVP - Visual C ++

< /块引用>




" SteveDB1" < St ****** @ discuss.microsoft.com写信息

新闻:CE ********************** ************ @ microsof t.com ...


Mark,

谢谢你的支持回复。

我已经用返回0替换了exit(); 

我仍​​然有基本相同的问题 - 它不允许我退出



函数。

我可以用零退出程序,但没有任何键的按键允许我
$ b函数$ b,如果我要退出,我必须通过单击cmd控制台窗口顶部的关闭''x'来关闭程序



我想在返回0问题之后我的第一个问题是,我会更好

关闭而不使用do-while,因为转义键不再允许我



曾经出过吗?

再次,谢谢你的帮助。



我错过了什么......我看不出在哪里/怎么样ch设置甚至是什么

变量类型。


马克


-

Mark Salsbery

Microsoft MVP - Visual C ++


>



Hi all.
I''m using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0 in
2001.
I''ve updated again this past month, and have found enough differences that I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?

My general form is:

------------------------------------------------------------------
# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898

int n;
int ParA, ParB, ParC, ParD, ParE;

using namespace std;

int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);

secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.

//return n; //where n is an equation within the core code.

exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);

secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}

int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.

Switch(ch)
{
case ''1'' : functionA(ParA, ParB, ParC, ParD);
break;
case ''2'' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case ''3'' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
}

解决方案

"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:8C**********************************@microsof t.com...

Hi all.
I''m using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0
in
2001.
I''ve updated again this past month, and have found enough differences that
I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?

My general form is:

------------------------------------------------------------------
# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898

int n;
int ParA, ParB, ParC, ParD, ParE;

using namespace std;

int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);

secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.

//return n; //where n is an equation within the core code.

exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);

secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}

int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.

Switch(ch)
{
case ''1'' : functionA(ParA, ParB, ParC, ParD);
break;
case ''2'' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case ''3'' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
}


exit() is for terminating the application, not to exit a function.
To exit a function, use return.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++



Mark,
Thank you for your response.
I''ve replaced the exit() with "return 0;"
I still have essentially the same problem- it will not allow me to exit the
function.
I can exit the program with a zero, but no keystroke of any key allows me
out of the function, and if I want to exit, I must close the program by
clicking the close ''x'' at the top of the cmd console window.
I guess my initial question following the return 0 issue, would I be better
off without using the do-while since the escape key no longer allows me the
out it once did?
Again, thank you for your helps.

"Mark Salsbery [MVP]" wrote:

"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:8C**********************************@microsof t.com...

Hi all.
I''m using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0
in
2001.
I''ve updated again this past month, and have found enough differences that
I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?

My general form is:

------------------------------------------------------------------
# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898

int n;
int ParA, ParB, ParC, ParD, ParE;

using namespace std;

int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);

secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.

//return n; //where n is an equation within the core code.

exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);

secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}

int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.

Switch(ch)
{
case ''1'' : functionA(ParA, ParB, ParC, ParD);
break;
case ''2'' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case ''3'' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
}



exit() is for terminating the application, not to exit a function.
To exit a function, use return.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++




"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...

Mark,
Thank you for your response.
I''ve replaced the exit() with "return 0;"
I still have essentially the same problem- it will not allow me to exit
the
function.
I can exit the program with a zero, but no keystroke of any key allows me
out of the function, and if I want to exit, I must close the program by
clicking the close ''x'' at the top of the cmd console window.
I guess my initial question following the return 0 issue, would I be
better
off without using the do-while since the escape key no longer allows me
the
out it once did?
Again, thank you for your helps.


I''m missing something....I can''t see where/how "ch" gets set or even what
type of variable it is.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

>



这篇关于退出一个函数()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆