简体   繁体   English

C ++(不使用MFC)检查ini读取值是否为空

[英]C++ ( Without MFC ) checking if an ini read value is empty

I am having a little trouble getting the my program to check whether or not a .ini file is empty or contains the path to a webpage. 我在程序检查.ini文件是否为空或包含网页路径时遇到了一些麻烦。

My .ini file: 我的.ini文件:

[WEB]
Location =

The following is my code. 以下是我的代码。 It will not enter the if statement and show the Dialogbox: 它不会进入if语句并显示Dialogbox:

GetPrivateProfileStringA("WEBSERVICES", "Location", "none set", webLocation, sizeof(webLocation), pathStr);

    if (webLocation == "1"){
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        EnableMenuItem(hmenu, ID_WEBSERVICES_RUN, MF_GRAYED);
        }

Any help on this issue would be appreciated. 任何有关这个问题的帮助将不胜感激。

Regards -Dan. 问候 - 丹。

The if condition is incorrect, use strcmp() to compare char arrays: if条件不正确,使用strcmp()来比较char数组:

if (0 == strcmp(webLocation, "1")){

This: 这个:

if (webLocation == "1"){

compares the address of webLocation to the address of the string literal "1" , which always will be false (in this case). webLocation的地址与字符串文字"1"的地址进行比较,字符串文字"1"始终为false (在本例中为)。

Note that the section name WEB does not match that specified in the call to GetPrivateProfileStringA() . 请注意,节名称WEBGetPrivateProfileStringA()调用中指定的名称不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM