Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 04:28

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++]IniRead Problem?

Discussion on [C++]IniRead Problem? within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2014
Posts: 28
Received Thanks: 0
[C++]IniRead Problem?

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?
reload! is offline  
Old 05/23/2014, 02:54   #2
 
davydavekk's Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 101
Received Thanks: 42
Do you want to get the file config.ini in the parent directory ?

If so :
Code:
ReadIni reader("..\\config.ini");
You forgot a dot ( . ).
davydavekk is offline  
Old 05/23/2014, 14:34   #3
 
elite*gold: 0
Join Date: Apr 2014
Posts: 28
Received Thanks: 0
Thanks for reply, but It's Same xD, the console write the default value : "Defalut"
reload! is offline  
Old 05/23/2014, 14:53   #4
 
​Tension's Avatar
 
elite*gold: 110
Join Date: Jun 2013
Posts: 599
Received Thanks: 510
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.
​Tension is offline  
Old 05/23/2014, 15:42   #5
 
elite*gold: 0
Join Date: Apr 2014
Posts: 28
Received Thanks: 0
The file config is in the folder, and i try with "config.ini" but not work D:
reload! is offline  
Old 05/23/2014, 16:19   #6
 
​Tension's Avatar
 
elite*gold: 110
Join Date: Jun 2013
Posts: 599
Received Thanks: 510
Could you post your Ini-File here?
​Tension is offline  
Old 05/23/2014, 17:11   #7
 
elite*gold: 0
Join Date: Apr 2014
Posts: 28
Received Thanks: 0
look up
reload! is offline  
Old 05/24/2014, 09:25   #8
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
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
Dr. Coxxy is offline  
Old 05/24/2014, 15:04   #9
 
elite*gold: 0
Join Date: Apr 2014
Posts: 28
Received Thanks: 0
Thanks all guys for reply i solved I want to start software by admin xD And no by Vs
reload! is offline  
Old 05/27/2014, 20:49   #10



 
+Yazzn's Avatar
 
elite*gold: 420
Join Date: Jan 2012
Posts: 1,082
Received Thanks: 1,000
Your code leaks. Just use boost's property tree instead (c++ - How to parse ini file with Boost - Stack Overflow).
+Yazzn is offline  
Reply


Similar Threads Similar Threads
IniRead - kleines Problem
09/14/2011 - AutoIt - 2 Replies
Hey Com, habe gerade ein kleines Problem mit AutoIt und mit SuFu nichts brauchbares/hilfreiches gefunden... AutoIT: IniWrite(@ScriptDir & "/Settings.ini","Koordinaten", GuiCtrlRead($SaveName),GuiCtrlRead($XKoord) & "|" & GuiCtrlRead($YKoord) & "|" & GuiCtrlRead($ZKoord)) Ini:
Problem mit IniRead und Hide/Show.
01/28/2011 - AutoIt - 4 Replies
Ich habe mich seit einer langen seit mal wieder an Autoit gesetzt und auch gleich etwas ordentliches versucht... nur bin ich nach kurzer Zeit schon auf die ersten Problemchen gestoßen... vorerst einmal der Script:
IniRead problem
08/13/2010 - AutoIt - 7 Replies
Hab mich weiter durch etliche tuts gequält auch in nem autoit forum gefragt aber so richtig bekommt keiner das hin HotKeySet("{ESC}","EXITT") $ini = "config.ini" $iniread = IniRead($ini,"Nutzung","ja/nein&quo t;,"ja","NotFound") If $iniread = "ja" Then $name = IniRead($ini,"Login","Name") $pw = IniRead($ini,"Login","PW")
IniRead~Input Problem
05/02/2010 - AutoIt - 2 Replies
mein 2ter thread,weil ich grad beim letzten Schritt daran verzweifel Mein Ziel ist es die gewuenschte Realmlist abzuspeichern in der .ini datei und auf Buttondruck wieder hervorzurufen und das 3 mal (sprich 3 Favoriten) hier der Script Es funktioniert alles soweit auch das speichern der Favoriten,nur das Aufrufen funktioniert nicht.



All times are GMT +1. The time now is 04:28.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.