I have an ini file that has this info: and this is my code:
#include "stdafx.h"
#include "iostream"
#include <stdio.h>
#include "IniReader.h"
#include "INIReader.h"
using namespace std;
int main(int argc, char * argv[])
{
INIReader reader("C:\SampleFile.ini");
if (reader.ParseError() < 0) {
cout << "Can't load 'test.ini'\n";
return 1;
}
std::cout << "Config loaded from 'test.ini': version="
<< reader.GetInteger("info", "CaptureDuration", -1) << "CaptureDuration"<<"\n"
<< reader.Get("info", "DayStart", `enter code here`"UNKNOWN") << ", email=";
cin.get();
return 0;
}
I also attached the INIReader header file that I found from this link: https://code.google.com/p/inih/source/browse/trunk/cpp/INIReader.h I want the code to print the integer and the string values that it got from the ini file. but I am getting Linker errors. How can I fix it?
Errors:
,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Get@INIReader@@QAE?AV?$
1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall INIReader::ParseError(void)" (?ParseError@INIReader@@QAEHXZ) referenced in function _main
@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>C:\Users\Owner1\Documents\Visual Studio 2008\Projects\inireader\Debug\inireader.exe : fatal error LNK1120: 4 unresolved externals
I do't see any lib file to link to this project, where should I get the lib files?
LNK2019 typically has one of the following reasons:
Edit: In this particular instance, you'll have to add the file IniReader.cpp to your project, as it provides the missing functions.
Use Windows API like GetPrivateProfileString
and WritePrivateProfileString
for reading .ini files. It works fine and does not require any libraries. I used it for decades.
The simplest way is:
inih
into your project directory (I think it is C:\\Users\\Owner1\\Documents\\Visual Studio 2008\\Projects\\inireader) inih
into your project in Visual Studio 2008 . The error's reason is like @Mario said. You just compiled your cpp file, but not compile other cpp files that is necessory for your project. So you also need to compile all .cpp files in inih
.
Note: I think you should read this to learn more about the compiling and linking of C.
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.