关于GetPrivateProfileInt的问题
如下代码
- C/C++ code
#include <windows.h>#include <iostream>#define aMethod 0x0001#define bMethod 0x0002#define cMethod 0x0003int main(){int Result = GetPrivateProfileInt("set", "method", 0, "F://set_method.cfg" );cout<<Result<<endl;}
set_method.cfg中数据如下:
[set]
method = aMethod | bMethod |cMethod
可是Result输出的结果是0,不是我想要的Result = aMethod | bMethod | cMethod的结果,该怎么解决?
很急,请求高手解答
[解决办法]
GetPrivateProfileInt()方法是获取整数,而楼主定义method = aMethod | bMethod |cMethod
明显是字符串么,要什么你就使用GetPrivateProfileString()方法
1.使用GetPrivateProfileInt()方法:
需要先定义一个Int变量 赋值为aMethod | bMethod |cMethod,然后保存Int变量的值到文件中再读取出来。
2.使用GetPrivateProfileString()方法:
需要先定义一个CString变脸,赋值为"aMethod | bMethod |cMethod",然后保存CString变量的值到文件中再读取出来。
另外你定义的
#define aMethod 0x0001
#define bMethod 0x0002
#define cMethod 0x0003
是否有问题啊
是否应该定义为
#define aMethod 0x0001
#define bMethod 0x0002
#define cMethod 0x0004
因为0x0001的二进制是00000001、0x0002的二进制是00000010、0x0003的二进制是00000011,你用这3个与运算肯定会有重复啊
而用0x0001的二进制是00000001、0x0002的二进制是00000010、0x0043的二进制是00000100才会无重复的表达2^3=8种情况啊