|
I have set the value in table as:
m_file.SetValue("DATA","File","cpc.dat",true);
now i read the value of "File" as:
m_file.readFile();
m_file.GetValue("DATA","File");
the value it returns is cpc.dat
now i want this value to be used in my file.so i want to store its value in CString type variable but it gets error of type string.
CString myvalue;
myvalue=m_file.GetValue("DATA","File");
How can i save this return value in CString type variable.
|
|
|
|
|
Try:
CString someString = m_file.GetValue("DATA","File").c_str();
or maybe
CString someString = CString(m_file.GetValue("DATA","File").c_str());
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
why .exe was inflated to 200k, after adding your code, while its original size is 45k. And how to reduce its size? (using vc6)
|
|
|
|
|
Were you using anythign from the STL prior to this class? If so, it may be since the linker did not add anything for the STL previously. Is this a debug or a release build size?
Its possible that there may be an option on how to link to the standard library in the project options, its been a little while since I've looked.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
MFC allows you to set the name of an INI file and thereby bypass the registry while allowing use of the built-in functions of Get/WriteProfileString, Get/WriteProfileInt etc.
The formatting of the INI file is standard and is done automatically by these MFC functions.
All you need to do is to set a value for CWinApp::m_pszProfileName, as described by MSDN at http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_cwinapp.3a3a.m_pszprofilename.asp[^]. MSDN also gives sample code, which would be included in CWinApp::InitInstance:
CMyApp::InitInstance()
{
free((void*)m_pszProfileName);
m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini"));
}
There's nothing more to do. Everything else is handled automatically. Even formatting of the INI file when you use MFC's Get/WriteProfileString, Get/WriteProfileInt etc functions.
Mike
|
|
|
|
|
I also inserted iniFile.cpp & iniFile.h into VC++ 6.0. I get compilation error as follows:
iniFile.cpp
c:\software\initest\inifile.cpp(32) : warning C4005: 'iniEOL' : macro redefinition
c:\software\initest\inifile.cpp(30) : see previous definition of 'iniEOL'
c:\software\initest\inifile.cpp(490) : fatal error C1010: unexpected end of file while looking for precompiled header directive
-------
Why won't it compile? Thanks.
|
|
|
|
|
To fix the actual error, either add the line
#include "stdafx.h" to inifile.cpp or turn off precompiled headers for it.
The warning... I don't think it will actually make a difference, should be able to ignore it.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I did what you suggested, so that error went away. But for some reason my compiler isn't recognizing the fstream functions.
c:\initest\inifile.h(113) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\iniTest\iniFile.cpp(47) : error C2079: 'f' uses undefined class 'basic_fstream<char,struct std::char_traits<char=""> >'
C:\iniTest\iniFile.cpp(52) : error C2228: left of '.open' must have class/struct/union type
C:\iniTest\iniFile.cpp(53) : error C2228: left of '.fail' must have class/struct/union type
C:\iniTest\iniFile.cpp(56) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 provided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
C:\iniTest\iniFile.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::
basic_istream<_E,_Tr> &' from 'int'
C:\iniTest\iniFile.cpp(56) : fatal error C1903: unable to recover from previous error(s); stopping compilation
iniTest.cpp
|
|
|
|
|
Hmm.. it looks like your version of Visual Studio (is that VC6? not sure if that is VC98 or not) has some differences with the standard library. I'm really not familiar with VC6's quirks regarding the STL. My suggestion would be to look in the MSDN that came with that version of Visual Studio with regards to the basic_fstream class and what the third argument expected by getline is.
I'm taking a guess based on the documentation with VS 2003, but you might try adding the third parameter to the calls to getline. Ex: change the line:
getline( f, line)
to
getline( f, line, f.widen('\n'))
I would first try fixing the first error before changing getline though. Since the variable 'f' is used in that call to getline, it could be that since 'f' is not being defined correctly (the basic_fstream error) it is messing up the getline as well.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I am adding CiniFile in my MFC (SDI) application.There comes no error and compilation is successfull but when i include iniFile.h in my View.cpp(CView),then 82 errors generated.so no function of this class is acceble in my view class.How it should be resume.
nzshi
|
|
|
|
|
Make sure you added the inifile.cpp to your project.
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
yah iniFile.cpp is included in the project:errors are like this
f:\srs of plantscape\savefile\inifile.h(32) : error C2146: syntax error : missing ';' before identifier 'path'
f:\srs of plantscape\savefile\inifile.h(32) : error C2501: 'string' : missing storage-class or type specifiers
f:\srs of plantscape\savefile\inifile.h(32) : error C2501: 'path' : missing storage-class or type specifiers
f:\srs of plantscape\savefile\inifile.h(34) : error C2143: syntax error : missing ';' before '<'
f:\srs of plantscape\savefile\inifile.h(34) : error C2501: 'vector' : missing storage-class or type specifiers
f:\srs of plantscape\savefile\inifile.h(34) : error C2059: syntax error : '<'
f:\srs of plantscape\savefile\inifile.h(34) : error C2238: unexpected token(s) preceding ';'
f:\srs of plantscape\savefile\inifile.h(35) : error C2143: syntax error : missing ';' before '<'
f:\srs of plantscape\savefile\inifile.h(35) : error C2501: 'vector' : missing storage-class or type specifiers
f:\srs of plantscape\savefile\inifile.h(35) : error C2059: syntax error : '<'
f:\srs of plantscape\savefile\inifile.h(35) : error C2238: unexpected token(s) preceding ';'
f:\srs of plantscape\savefile\inifile.h(36) : error C2143: syntax error : missing ';' before '<'
f:\srs of plantscape\savefile\inifile.h(36) : error C2501: 'vector' : missing storage-class or type specifiers
nzshi
|
|
|
|
|
Try adding the following line in inifile.h somewhere after the includes, but prior to the class declaration:
using namespace std;
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
yah..its working now.thanx a lot.
|
|
|
|
|
I used to run the CIniFile class in WinXP and everything was working great. But now that I have to use it on a Win98SE computer, it doesn't seem to work anymore.
Does anyone know why this is happening?
Thank you.
|
|
|
|
|
What "doesn't seem to work anymore"?
What is it doing?
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
I use comments a lot in ini files and I noticed that the comment after a string, on the same line, was not filtered from the value. The code below fixes this and also trims the value left and right. A restriction is of course that the string may not contain the chars '#' or ';' as this will be seen as comment!
Change code of iniFile.CPP at line 85 into this:
<br />
case '=':<br />
valuename = line.substr( 0, pLeft);<br />
value = line.substr( pLeft + 1);<br />
if (value.size() && value.find_first_of(";#")!= string::npos) <br />
value.erase(value.find_first_of(";#"));<br />
value.resize(value.find_last_not_of("\r\n \t") + 1); <br />
value.erase(0, value.find_first_not_of("\r\n \t")); <br />
SetValue( keyname, valuename, value);<br />
break;<br />
Greetings Dennis.
|
|
|
|
|
I would like to know if ther is a way to support unicode file by this code!!
In fact if you change some definitions with wifstream and wstring and some artifacts..
i could not be possible to complie the class !!
There is an error on wifstream which don't use a wchar as first param ??
|
|
|
|
|
Can you post the exact error, and maybe some details about the code you changed?
Thanks
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
Hye!!
I use your files but i still have 5 warnings:
c:\program files\microsoft visual studio\vc98\include\vector(39) : 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(39) : 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> > > >(const std::allocator<std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\vector(39) : 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(39) : 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> > > >(const std::allocator<std:
:basic_string<char,std::char_traits<char>,std::allocator<char> > > &)'
Generating Code...
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: '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> > >
>::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> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: '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> > >
>::~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> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(52) : warning C4786: '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> > >
>::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> > > >' : identifier was truncated to '255' characters in the debug information
Do you know how can I get rid of theses warnings?
Thank you a lot.
|
|
|
|
|
Please see:
http://www.codeguru.com/forum/showthread.php?s=438df56fb6990cc9dfb4fa38be92c5d5&threadid=232164
|
|
|
|
|
Why not use API Function GetPrivateProfileString WritePrivateProfileString
|
|
|
|
|
We had a discussion about this a while back. See:
http://www.codeproject.com/cpp/cinifile.asp?select=229342&df=100&forumid=619&fr=26#xx229342xx
Adam Clauss
cabadam@tamu.edu
|
|
|
|
|
Good work, but problems occur when two distinct processes are reading/writing the same INI file. So support for synchronization should be added.
yoko
|
|
|
|
|
This worked good with VC++ 6. I moved it to VS.NET 2003 and I get 26 build errors.
The .cpp compiles fine but I get 26 errors in every file that I "include iniFile.h" all the erros relate to string
c:\Documents and Settings\Kevin\My Documents\Julie\IniFile.h(32): error C2146: syntax error : missing ';' before identifier 'path'
this refers to the code "string path;"
I am sure I am missing something simple but I can't find it. Any ideas???
Thanks
|
|
|
|
|