c++中运行结果窗口加了system("pause")还闪退怎么办

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int c;
void main()
{
int a=1;
int b=2;
c=a+b;
}
int demo(void)
{
cout<<c<<endl;
system("pause");
return 0 ;
}

你没有运行demo( )。
在主程序中加:
demo();

return 0;

函数不会自动调用的。 在函数demo( )中写 system("pause"); 不调用又有什么用呢?

你demo( )中的return 0; 是为函数demo( ) 返回了0;主函数没有return和system(“pause”),运行完当然自动结束了。追问

哦哦,我明白这个了,那我还想问一下在MFC中要将一个函数的值用到另一个函数中要怎么办?我定义了一个全局变量,但发现函数中的值没能传到全局变量中,所以在下一个函数中也就不能用了。

追答

没有传到全局变量中?
你怎么样传的?语句发出来。
有必要的话发程序。

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答