简体   繁体   中英

Read ini file in C++ using 64 compiler

I want to read ini file in C++ using 64 bit compiler of visual studio, and GetPrivateProfileString() doesn't work for 64 bit compiler it just work for Win32. Is there any way to read such file other than using GetPrivateProfileString() ??

GetPrivateProfileString() doesn't work for 64 bit compiler it just work for Win32.

This is absolutely incorrect. Virtually all of the Win32 functions are available as 64-bit versions, and GetPrivateProfileString is no exception. If you are unable to make it work, then the code that you have written is wrong. Unfortunately, you didn't show that code, so we can't tell you how to fix it.

Do make sure that you are passing a fully-qualified path to the file when trying to call this function! Relative paths will not have the desired effect.

However, you should probably not be using GetPrivateProfileString anyway. As the documentation says:

Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.

INI files are still sometimes a reasonable choice— eg , as settings files for "portable" applications for which you do not want to modify the registry—but you should still not use the Windows Get/SetPrivateProfile* API functions to read and write these files. They are very old, ported directly from 16-bit Windows, and contain lots of unexpected behavior for backwards-compatibility reasons. They are also slow and offer very limited features.

Although there are many alternatives, my personal recommendation would be the SimpleINI library . This is cross-platform, uses the C++ standard library, and has been released under the MIT license. Just drop it in and start using it. I works well; I use it in one of my MFC applications.

You could also use Boost to read INI files.

I can't comment yet, so I'm answering.
GetPrivateProfileString() works perfectly for me under Visual Studio 2015 on any platform, Win32 as well as x64, and on any charset UNICODE or MBCS.
Double check your code, or post it so we can have a look.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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