![]() |
INI-file reader
I am stucked with a very frustration problem. The program crashes on the getline(...) row. Any ideas why?
:
#include <iostream>The INI file look like this: :
[general] |
Ok, I solved it after a chat with a friend. I changed the char* tmp to a char tmp[32].
|
Hi,
do you know why it crashed ? if not i'll tell you. You did not allocate space for your buffer, so getline tried to write date into memory which did not belong to you. That is where the "big bang" kicked in. |
Ah, thanks!
Is there a way to solve it? Use of malloc(), or something like that? |
Hi,
yes there is a way. As you are coding in c++ new is the operator you'll want to use. just allocate buffer this way: :
char *tmp=new char[32] ;//or whaterver sizeA better way to do things where exception conditions are likly to accure, is to use smart-pointers which exploit RAII to assure that any resources previously acquired are released in all circumstances. Hope it helped ... So far ... |
Yes, it helped!
Thanks alot! |
Unless this is just for learning, there are win32 functions for reading in an .ini file. Look up GetPrivateProfileString(), and its close related functions.
|
Yes, it is just for learning. Actually I read about that function, and thought that "I do it myself instead"! I am also coding for BeOS, so I want portable code.
Thanks anyway! |
Hi Klarre,
if you want something more powerful you could use boost:: program_options for *nixes or boost::serialization for win32 and *nixes. |
I would normally use the 'string' data type in this instance, instead of char*
|
| All times are GMT -5. The time now is 4:24 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC