全局变量的定义方法

设:工程名为Project 
在这里说两种方法:
1、在主对话框和模态对话框中的cpp文件里定义
在父对话框CPP文件中,即ProjectDlg.cpp中定义全局变量str,格式为CString Str;(注意:位置在顶端#endif的后面,很多同学把位置写错了,所以定义的也就没作用了)。
然后在模态对话框中CPP文件中用下面语句
       extern CString Str;     //定义共享变量Str    (代码位置同上)
2、在stdafx.h 里定义
首先在 stdafx.h 里定义
extern CString Str;     //定义共享变量Str
然后在stdafx.cpp中写入    CString Str;
发布了35 篇原创文章 · 获赞 17 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/shaopengf/article/details/40656765
今日推荐