[C++]IniRead Problem?

05/22/2014 19:34 reload!#1
Hi guys ;) I have a problem to read the ini file :
PHP Code:
//ini.cpp
ReadIni::ReadIni(char *szFileName)
{
    
memset(m_szFileName0x00255);
    
memcpy(m_szFileNameszFileNamestrlen(szFileName));
}

charReadIni::String(char *szSectionchar *szKey, const char *szDefaultValue)
{
    
char *szResult = new char[255];
    
memset(szResult0x00255);
    
GetPrivateProfileString(szSectionszKeyszDefaultValueszResult255m_szFileName);
    return 
szResult;

And ..
PHP Code:
//ini.h
class ReadIni
{
private:
    
char m_szFileName[255];
public:
    
ReadIni(char *szFileName);
    
char *String(char *szSectionchar *szKey, const charszDefaultValue);
}; 
In the main, when i put this code :
PHP Code:
ReadIni *Read = new ReadIni(".\\config.ini");
    
std::string read Read->String("Section","Key","Defalut");
    
std::cout<<read<<std::endl
The console write the default value : "Defalut", how i to do for the console write the value that is in the config?
05/23/2014 02:54 davydavekk#2
Do you want to get the file config.ini in the parent directory ?

If so :
Code:
ReadIni reader("..\\config.ini");
You forgot a dot ( . ).
05/23/2014 14:34 reload!#3
Thanks for reply, but It's Same xD, the console write the default value : "Defalut"
05/23/2014 14:53 ​Tension#4
Is the config.ini in your folder? If yes, remove the ".\\".
And i would rename the function called "String" into something like ReadString ( just my opinion ).
If it still fails you could use the function GetLastError to receive the error code.
05/23/2014 15:42 reload!#5
The file config is in the folder, and i try with "config.ini" but not work D:
05/23/2014 16:19 ​Tension#6
Could you post your Ini-File here?
05/23/2014 17:11 reload!#7
look up
05/24/2014 09:25 Dr. Coxxy#8
1.: ".\\config.ini" is totally correct.
2.: your working dir is not the path of the compiled exe file if you run it through the visual studio debugger! ".\\" will be the project path instead.
3.: use strcpy(_s) in your constructor.
4.: your ini should look like this:
Code:
[Section]
Key=asdf
05/24/2014 15:04 reload!#9
Thanks all guys for reply i solved ;) I want to start software by admin xD And no by Vs :)
05/27/2014 20:49 +Yazzn#10
Your code leaks. Just use boost's property tree instead ([Only registered and activated users can see links. Click Here To Register...]).