|
Well your code (though a bit weird: duplication) works on my system.
BTW why don't you delete the allocated memory?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
how????
did u tried it multiple times...
and in both way worked???
please i really need to know whats wrong...
|
|
|
|
|
Yes it actually works.
I've made three tests:
(1) Button1 followed by Button2 (loaded two different files)
(2) Button2 followed by Button1 (loaded two different files)
(3) Button1 followed by Button2 (loaded the same file)
All of them were OK.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ok...
what version of vc r u using>>>>>iam using 6
someone else tried it also and it didnot work out
|
|
|
|
|
Are you kidding?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no iam not .... iam serious
whats wrong????
|
|
|
|
|
Well, I'll try also on VS6 . Maybe this evening (here I've only VS2005 ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm not real familiar with code on the heap, but the statement
char* sText = new char[nFileLong+1]; //reserve string space
is created with "new". Doesn't that require a "delete" or equivalent (I don't know the syntax) to de-allocate that space? If you don't then that space can't get re-allocated since the pointer is lost when you exit the procedure. Don't know what kinds of problems could occur as a result.
|
|
|
|
|
One problem your code has is in the method you are opening the files with fopen. There are two modes for reading and writing to files - binary mode and text mode. Some character conversions change in those two modes. When you open file1 and file2 you do not specify what mode to use, so the default mode is used. When you open m_sFileName you tell it to open it to read in binary mode instead of text mode.
Try changing the "w" to "wt" in this statement of yours
FILE *file1 = fopen("file1.txt","w");
And more importantly change the "rb" to "rt" since you are trying to read characters in the following statement in your code
fp=fopen(m_sFileName,"rb"); //Open file for reading
The ftell and fseek functions may not give the correct lengths if the file is opened in text mode, however. So you should simplify things and use the fgets() function to get the string you want.
Since you are working with text files they should be opened with the text attribute.
modified on Tuesday, June 24, 2008 6:30 AM
|
|
|
|
|
i created following code.
template <typename t>
class c{
public:
int f1(){ fp=f1; return 1;};
char* f2(){ fp=f2; return "hi";};
t recentFunction(){ return fp(); }
private
t (*fp)();
}
is it validity?
i wanna get a code for recentFunction
i do not know how to implement compounding funtion point and template
pleae help me
|
|
|
|
|
Try something like this.
template <typename t> class c
{
public:
typedef t (c::*FuncPtr)();
int f1()
{
mFp=&c::f1;
return 1;
}
char* f2()
{
mFp=&c::f2;
return "hi";
}
t recentFunction()
{
return (this->*mFp)();
}
private:
FuncPtr mFp;
};
Test it using this.
c<int> c1;
c<char*> c2;
c1.f1();
int x = c1.recentFunction();
c2.f2();
char* ret = c2.recentFunction();
If you want to read more about member function pointer search for delegates. There are numerous articles on this topic on codeproject. One of them is Member Function Pointers and the Fastest Possible C++ Delegates[^].
-Saurabh
|
|
|
|
|
This question is difficult to ask. The concept is simple, but the details of explaining it just go on and on.
Using Visual Studio 2008, I have created an application with MFC. In this application there is to be a linked list of instantiated objects. This list is to live the lifetime of the program and be publically accessible.
Not being familiar at all with the windows concept, where do I instantiate/create this object? There is no place within the code that VS created that I recognize as being something that can hold a permanent variable.
If the question is clear at this point, you might want to stop reading now. I am confused so the remainder of this post may be even more confusing.
The base class that VS created is listed below. Where should I insert something like:
CMyClass myinstance = new( CMyClass );
Or maybe:
CMyClass myinstance;
I want that because in another class I wish to write:
CMyClass::myinstance.LinkNewItem( new_item );
Hopefully this will cause a new item to be linked in to the linked list and other code can traverse the list to work with the data.
It none of this is appropriate, please advise as to what is appropriate.
Here is the cpp file that VS created. Where does my code belong?:
// test1.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "test1.h"
#include "test1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Ctest1App
BEGIN_MESSAGE_MAP(Ctest1App, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// Ctest1App construction
Ctest1App::Ctest1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only Ctest1App object
Ctest1App theApp;
// Ctest1App initialization
BOOL Ctest1App::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Ctest1Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
Thanks for your time
|
|
|
|
|
It seems you are creating a dialog based application. In that case you can put your data in the dialog class. In the example code you provided in the Ctest1Dlg which should be in the files test1Dlg.h and test1Dlg.cpp.
-Saurabh
|
|
|
|
|
I've tested when saving and loading, right, but not sure wheather it is always safe.
void CMyDoc::Serialize(CArchive& ar) {
CFile *pFile = ar.GetFile();
CString path = pFile>GetFilePath();
TCHAR buf[MAX_PATH];
DWORD dw = GetPrivateProfileString(m_sec,m_key,NULL,buf,MAX_PATH,path);
...
}
|
|
|
|
|
An INI file should have nothing to do with serializing CObjects. So it should be safe, but as always it depends on what the developer does.
|
|
|
|
|
When saving, the frameword open the file in mode
CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive ,
but the GetPrivateProfile still works
|
|
|
|
|
h3y hI every1 i am sorry for this childish question but actually i got a task to perform directory manipulation ... i have created folder by using _mkdir nd remove the folder my using _rmdir .. But i dont know how to show all the content of directory mean i have to show all files name in that folder and all directory names in that folder could any one help me .. i am using visual studio 2005 .. c++ Only in c++ no windows API no MFC nO <direct.h> Just purly c++ .. please reply me back
|
|
|
|
|
Member 3831312 wrote: c++ Only in c++ no windows API no MFC nO Just purly c++
Sorry. There are no "standard" C++ facilities to iterate through files or folders/directories. You have to use an interface to the operating system to do that (.NET, Win32 SDK, etc for Windows platforms; Unix/Linux has their counterparts).
Or, you can use a 3rd-party library (such as Boost) and use their interface.
Enjoy,
Robert C. Cartaino
|
|
|
|
|
Thanks FOr reply Robert ... Please tell me one thing more i am using 3rd party library booost ... but i cause me an error while compiling it says ,
"fatal error LNK1104: cannot open file 'libboost_filesystem-vc80-mt-gd-1_35.lib'"
do u have any idea about it ... hOw can i resolve it .. i have linked all the important path that i have to give but still its not working .. please do hit me back
thanks
|
|
|
|
|
The problem is clearly stated in the error message: the linker can't find the file "libboost_filesystem-vc80-mt-gd-1_35.lib". So two questions occur:
1. Has this file been built (Boost.FileSystem is NOT a header only library)?
2. Has the path to this file been specified in the project settings?
Steve
|
|
|
|
|
H3y hi every1 please help me out i am Just creating a small program in c++, which is use to show all the content Of a directory .. i am Using BOOST LIBRARY beacuse there is nO other option for e if there nay other option plzz do tell me and tell me how to resolve this prob actually prog is compiling but i dont know whats wrong its keep on giving this Error i am Using Visual STudio 2005 ... please help me
|
|
|
|
|
Download and install "BoostPro 1.35.0 Installer" from this site.
http://www.boostpro.com/products/free[^]
Then link with the library "libboost_filesystem-vc80-mt-gd-1_35.lib" which is included with the installer.
-Saurabh
|
|
|
|
|
thanks FOr reply But my dear brother i have already installed that but still itx not working i dont know about the prob PLzz help me
|
|
|
|
|
Have you linked the lib file in the Project-->Settings menu as Saurabh.Garg told you above?
|
|
|
|
|
yes i have linked the folder of lib in addition libraris . but still not working
|
|
|
|