|
I'm compiling with Visual Studio .NET and everything is working fine (thanks for this handy class!), but I got a bunch of seemingly unnecessary warnings.
Basically, it's mostly warnings about conversions from size_t to unsigned int that might loose data. You might not have seen this if you're using another compiler where the underlying data type is the same, but Visual Studio .NET apparently use 64-bit ints for the size_t type.
My suggestion is to do this:
Change return type from "unsigned" to "size_t" for:
- NumKeys
- GetNumKeys
- AddKeyName
- NumValues
- GetNumValues
- NumHeaderComments
- NumKeyComments
There's also a place where an integer is recast to a bool, where the compiler once again complains. GetValueB currently returns this:
bool(GetValueI(...))
but perhaps should return
GetValueI(...) ? true : false;
With these changes, the class compiles with 0 warnings.
|
|
|
|
|
I want to use CIniFile in my MFC Application.
|
|
|
|
|
CString cstring = "Test";
std::string str = (LPCSTR)cstring;
cstring = str.c_str();
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
Hi Adam,
When trying to build my project together with your files, I get an "unexpected end of file" error.
What can you suggest?
Than you, dushkin.
|
|
|
|
|
In Solution Explorer (or File View if you are using VC6), 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".
OR
At in iniFile.cpp, add the line #include "stdafx.h" to its list of includes.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
After adding the namespace, everything went fine!
|
|
|
|
|
Hi I am sure this is a simple error but just can't figure out how to fix it up. All I have done is included the header file for the CIniFile class in my main.cpp file, and copied all three files (iniFile.h, iniFile.cpp and Makefile) into the directory where main.cpp is.
I have also got this bit of code in my main.cpp:
CIniFile iniFile( "ini_test.ini");
I have also tried to create the object iniFile with no string passed into the constructor to initialise the path and used the SetPath("filename") function to get the same error but twice, once for the constructor and once for the SetPath() function. Anyone know the problem?
I am using Borland C++ Builder 6, making normal Applications.
This is the code I have typed into the relevant sections:
main.cpp:
#include "iniFile.h"
void __fastcall TForm1::FormCreate(TObject *Sender)
{
CIniFile iniFile( "ini_test.ini");
}
and this is the error i am getting:
[Linker Error] Unresolved external 'CIniFile::CIniFile(const _STL::basic_string<char, _stl::char_traits<char="">, _STL::allocator<char> >)' referenced from D:\STUFF\UNI STUFF\EEET2093\_CODE\6\MAIN.OBJ
Thanks anyone who can help me!
|
|
|
|
|
Well, I'm not too familiar with Builder, but if you are using a project of some form, make sure iniFile.cpp is added to it. Just having iniFile.cpp in the directory isn't enough - you have to tell the compiler to actually compile it.
If that doesn't work, then you will need to do some rearranging with my class.
Keep the #include "iniFile.h" from your main.cpp as it is. Open iniFile.h and at the END of that file, add #include "iniFile.cpp". In iniFile.cpp, REMOVE the line #include "iniFile.h"
I think that should work... (maybe...). Might need a couple other minor changes, not sure.
Let me know if that helps.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
im a newbie to c++(excuse me if this is a silly error)
I add the CIniFile class and i get this error
error C2533: 'CIniFile::CIniFile' : constructors not allowed a return type
please help
thanks in advance
vish
|
|
|
|
|
What line does it say you are getting this error on?
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
:-DI'm not sure why i got this error, but anyway i copied both .CPP and .H file and now it is working fine.
CIniFile::CIniFile( string const iniPath)
>>{
Path( iniPath);
caseInsensitive = true;
}
the line marked >>. i could not find any return type on that line...
anyway itz working now
thanks for the great code.
thankx
vish
|
|
|
|
|
Hehe, thats wierd. Glad its working
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
add a ; after your class declaration:
class foo
{
foo ();
~foo ();
}; <<<<<<<<<<<<<<<
Johnny.
|
|
|
|
|
Thanx for your help,
It was quite valuble to me.
APRZAVERI
|
|
|
|
|
Hey,
the new code is very nice and all, but STL's string doesnt work very well with CString so why not post the old code as well and let the developers decide which they like better.
I found your original code very usefull and had only to change it slightly to make it fit all my needs.
|
|
|
|
|
What kind of problems are you having getting CString to work with std::string?
Conversions between the two should be easy:
string s;
CString s2;
s = (LPCSTR)s2;
and
s2 = s.c_str();
The reason I took the old code off was because the new code contains the same functionality plus new additional features (that and the fact that it is much more portable). If you'd like, I can email the old code. I no longer actually use it in any projects though.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
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)
|
|
|
|
|