|
Well,
The problem is memory managment. since both string implementations use reference counts to manage memory (or so i'm told) mixing the two means that i need to start worying about allocating memory and freeing stuff when i return std:string from a function and assign it to CString variable.
I know it's not big, but it's something.
As for sending the code, i already got it (and modified it, and using it quite successfully), so thank anyway. The reason i suggested you post the old code as well is to give future generations a chance to see how similar functionallity can be done using CString.
anyways, no need to ponder over the matter, if you prefer to keep only the new code, well, hey, it's YOUR code
/NL
|
|
|
|
|
Hmm... I honestly can't say for sure about whether you need to free memory. I have not experienced any memory leaks before, so I assumed not. Maybe someone else here can say for sure?
Well, as far as the new code goes, if I start getting a fair number of people requesting it (like I did for the non-MFC version), I'll post it as well.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
sorry newb problem.
Visual c++ 6 gives me 400+ syntax errors on string variables when compiling, would it be okay to simply convert all to CString or is there a better solution ( I am sure there is)
|
|
|
|
|
I too get these errors. Could it be caused by you not using Microsofts STLport? If I don't here from you I will try this out.
Darroll
Not one person lives in the present. Only the past. I can prove it.
|
|
|
|
|
I too got these error? How did you solve it?
this is part of the list of the errors...
Compiling...
memleak_test.cpp
c:\proy\ini\more ini\inifile\test\inifile.h(38) : error C2065: 'key' : undeclared identifier
c:\proy\ini\more ini\inifile\test\inifile.h(38) : error C2955: 'vector' : use of class template requires template argument list
c:\archivos de programa\microsoft visual studio\vc98\include\vector(244) : see declaration of 'vector'
c:\proy\ini\more ini\inifile\test\inifile.h(38) : error C2133: 'keys' : unknown size
c:\proy\ini\more ini\inifile\test\inifile.h(38) : error C2512: 'vector' : no appropriate default constructor available
c:\proy\ini\more ini\inifile\test\inifile.h(38) : error C2262: 'keys' : cannot be destroyed
c:\proy\ini\more ini\inifile\test\inifile.h(41) : error C2270: 'CheckCase' : modifiers not allowed on nonmember functions
c:\proy\ini\more ini\inifile\test\inifile.h(43) : error C2143: syntax error : missing ';' before 'public'
c:\proy\ini\more ini\inifile\test\inifile.h(46) : error C2588: '::~CIniFile' : illegal global destructor
c:\proy\ini\more ini\inifile\test\inifile.h(46) : error C2575: 'CIniFile' : only member functions and bases c
|
|
|
|
|
I too get these errors. Could it be caused by you not using Microsofts STLport? If I don't hear from you I will try this out.
Darroll
Not one person lives in the present. Only the past. I can prove it.
|
|
|
|
|
I dont know what the hell that means but I wish u luck
|
|
|
|
|
Add the line:
using namespace std;
Either add it in the iniFile.h file (after the includes). I think you can also add it just prior to including the .h file in your program.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I now get this
-------------------Configuration: MovieBase - Win32 Debug--------------------
Compiling...
MainFrm.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.h(115) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
MovieBase.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.h(115) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
MovieBaseDoc.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.h(115) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
MovieBaseView.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.h(115) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
NewDatabaseDlg.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.h(115) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(58) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::~std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'
iniFile.cpp
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.cpp(32) : warning C4005: 'iniEOL' : macro redefinition
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.cpp(30) : see previous definition of 'iniEOL'
c:\program files\microsoft visual studio\myprojects\moviebase\inifile.cpp(488) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...
Error executing cl.exe.
MovieBase.exe - 1 error(s), 16 warning(s)
|
|
|
|
|
For the warnings - these are a known issue with the STL. They don't really mean anything. See:
http://www.codeguru.com/forum/showthread.php?s=438df56fb6990cc9dfb4fa38be92c5d5&threadid=232164
For the error at the end, you can do one of two things.
Either add:
#include "stdafx.h" as the first include in iniFile.cpp OR
In File View (or Solution Explorer if you are using VC.NET) right click on iniFile.cpp and go to properties. Turn off precompiled headers for this file (will not affect the rest of the project).
I typically do the second method.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
jobs a goodin
|
|
|
|
|
I am using VC.NET and cant find "Turn off precompiled headers for this file (will not affect the rest of the project)."
why. is there anything wrong with my compiler?
|
|
|
|
|
In Solution Explorer, right click on iniFile.cpp and go to properties. On the left, click the folder for C/C++ and then select Precompiled Headers. Now on the right, change where it says "Use Precompiled Header" to "Not Using Precompiled Header".
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I submitted an update that should be posted here in a couple days. There has been enough interest in the non-MFC version of this class that I have decided to post it here.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
The update looks good. I have been using the MFC version of the class for a while. It is very nice and I have actually ended up using it for a log of my projects as well... The one feature I felt was missing was the ability to store lists of values. I ended up modifying the class slightly to include SetValueList, and GetValueList functions. A list would be identified by a key name, and the values in the list would just appear in the ini file as n0, n1, n2, ... Is this an update that has been considered?
jonathan
|
|
|
|
|
No, I hadn't really considered doing that. I guess I figured it would be just as easy to either parse the string value returned. I've also seen other programs use a format similar to this (not with my class, though it could easily be done):
[SomeKeyName]
ListCount=5
Value1=...
Value2=...
Value3=...
Value4=...
Value5=...
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
Great class.. Thanks for sharing it with us!
Rob
|
|
|
|
|
Truely great class! In your demo, though, there is one simple bug in the OnInitDialog(). You had:
<code>age.SetWindowText(inifile.GetValue("Info","Age"));
This wouldn't load the age. The code for age is:
<code>age.SetWindowText(inifile.GetValue("Info<big>1</big>","Age"));
Again, not a big deal, but in case anyone was questioning the ability of your class, it was just a coding mistake.
Thanks a lot (I've been needing a class like this for a LONG time),
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
How can I get the text inputted into the ini file and save it to a CStirng?
Appreciate it ,
NightBlade
|
|
|
|
|
SetValue/GetValue?
Not sure if this is what you were asking, if it isn't please explain.
HTH,
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I tried doing the example:
CString GetValue(CString, CString)
but it gives me the error that "GetValue" is an undeclared identifer. I'm not sure why its doing that, thats my i asked. All the other functions work fine. So if there is somthing that I am not doing, I can't catch it
Thanks
NightBlade
|
|
|
|
|
Adam I am looking to change it so that it can access random ini keys ie
i am writing an app which records company account codes in a ini file for report purposes
ie it needs to load the account codes to setup a select statement to produce the reports
[codes]
acc1=syscode1
acc2=syscode2
acc3=syscode3
problem is the account code will vary and the syscode will vary
so i cant write something which pickup all the keys for a given section ,i can however count them.
I will email u if i can get it adjusted to cope !!
|
|
|
|
|
Hi,
I'm using your class with NT 4.0. It works very well.
I've got problems with my software running with Windows 95. Is CIniFile can work with Win95 ?
|
|
|
|
|
Hmm... I can't say I've personally tested it with Windows 95. I also haven't even used 95 in a long time.
What kind of problems are you experiencing?
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
Yes no problem. I've used it with every 32 bit version of windows except Windows .net server and Windows nt 3.x
|
|
|
|
|