|
I dont think writing to file in the following manner works. My sugeestion is to iterate through the map, take each structure, write each element of the structure seperately. While reading do the revers.
Did you check what sizeof(Map1) returns?it will return only 12/16 bytes.
nave
|
|
|
|
|
Hi,
I am getting problem with system menu when application is running on
64Bit PC with 64 bit os.
The problem is "System menu close button is disabling when application
is minimized and maximized".
This code is working fine with 32 bit Machine and 32 bit OS.
Please help for solving this problem.
Thanks,
Brahma.
Are
|
|
|
|
|
I am trying to create a file of bytes from my character array
const char* chars with length int count.
I wrote the C++ code:
FileStream file = new FileStream(S"chars.dat", FileMode::Create,
FileAccess::Write);
BinaryWriter binary = new BinaryWriter(file);
binary.write(chars, count); //it might just be binary.write(chars)
binary.close();
My compiler doesn't recognize FileStream and BinaryWriter, and when I try:
using namespace System::IO;
the compiler says that a namespace with this name does not exist.
Is my code correct, and what "using" or "include" do I need?
Also, I copied new FileStream(S"pixels.dat",...) from somewhere and I
don't know what the "S" means?
(By the way, I will later want to read this file in Java using DataInputStream.)
Thanks for reading this.
|
|
|
|
|
You are mixing languages.
- If you want to use the FileStream class then C# will be appropriate.
- If the chosen language is C++ then use std::fstream (or a C-like FILE * ).
- You can also use managed C++ to access FileStream class, but it is not the simplest solution.
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.
|
|
|
|
|
why you are not trying with fwrite?
|
|
|
|
|
Well, thanks for suggesting doing it in a simpler way.
My standard C++ code is now:
fstream file;
file.open("chars.dat", ios::out | ios::binary);
file.write(chars, count);
file.close();
and it works!
|
|
|
|
|
Im trying to improve my STL skills at the moment and wondered of there is a nice way to do the following.
I have a map that maps a string to an integer. I use it to count the number of times I get specific message for an entity identified by the string. What I want to do is find the string with the highest count. Obviously I can do this by itterating through the map but I wondered if its possible to do it another way?
|
|
|
|
|
Josh Gray wrote: but I wondered if its possible to do it another way?
Like keeping a reference to the one with the highest count.
led mike
|
|
|
|
|
led mike wrote:
Like keeping a reference to the one with the highest count.
I was hoping for some nice use of the algorithm stuff, like a combination of for_each and ????
Im just playing around with some unit tests and a tad bored
|
|
|
|
|
Josh Gray wrote: Im just playing around with some unit tests and a tad bored
Ah, ok, just don't give yourself any bad habbits like forgetting the KISS principle. (Keep It Simple Stupid)
led mike
|
|
|
|
|
This falls outside of STL, but you could use Boost MultiIndex[^] with a hashed unique index for the messages and an ordered non-unique index for the counts.
|
|
|
|
|
Hi,
you could use the following simple code
std::vector<std::string> vWords;
vWords.push_back("the");
vWords.push_back("eye");
vWords.push_back("of");
vWords.push_back("the");
vWords.push_back("tiger");
vWords.push_back("the");
vWords.push_back("eye");
vWords.push_back("of");
vWords.push_back("the");
vWords.push_back("beholder");
std::map<std::string,int> mapCheck;
int iMax = 0;
std::string strMaxWord;
for(std::vector<std::string>::const_iterator cIndex = vWords.begin(); cIndex != vWords.end(); Index++)
{
mapCheck[*cIndex]++;
if(mapCheck[*cIndex] > iMax)
{
iMax = mapCheck[*cIndex];
strMaxWord = *cIndex;
}
}
I hope that this helps or at least point you in the right direction
codito ergo sum
|
|
|
|
|
Hi
I am trying to understand the function of m_pMainWnd. But i have a problem.
For example
BOOL CMyApp::InitInstance()<br />
{<br />
CMyWindow *MyWindow = new CMyWindow();
m_pMainWnd = MyWindow;
MyWindow->Create(NULL, L"window");<br />
MyWindow->ShowWindow(m_nCmdShow);<br />
MyWindow->UpdateWindow();<br />
return TRUE;<br />
};
1-) What is happening in m_pMainWnd = MyWindow assignment so window does not close immediately? Is this assignment call some functions in CwinThread class? Or something else?
2-) Also this is very interesting for me and i do not understand why it is so.
I assigned m_pMainWnd MyWindow object that derived from CFrameWnd class so m_pMainWnd holds CFrameWnd object but m_pMainWnd->Create(...) calls Cwnd::Create not CFrameWnd::Create ? Why is it so? How can it be?
Can you please help me to understand this assignment.
I am looking for your answers...
|
|
|
|
|
After you have returned from the CMyApp::InitInstance(), the AfxWinMain() function calls the Run function of CWinApp. In that there is checking as shown below
int CWinApp::Run()<br />
{<br />
if (m_pMainWnd == NULL && AfxOleGetUserCtrl())<br />
{<br />
TRACE0("Warning: m_pMainWnd is NULL in CWinApp::Run - quitting application.\n");<br />
AfxPostQuitMessage(0);<br />
}<br />
....<br />
}
Now i think you undertand why your program didnt worked, when you comment that code.
nave
|
|
|
|
|
Hmm ok Thank you very much.
So
MyWindow->ShowWindow(m_nCmdShow);
MyWindow->UpdateWindow();
lines are working but when the program exit scope it terminate the program.
Can you please tell me the .cpp file of this code?
Also Why does m_pMainWnd->Create(...) call Cwnd::Create not CFrameWnd::Create?
Thanks for answer.
|
|
|
|
|
sawerr wrote: lines are working but when the program exit scope it terminate the program.
Yes
sawerr wrote: Can you please tell me the .cpp file of this code?
"Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP "
m_pMainWnd is a pointer of class CWnd*. So it will call the function of CWnd is it. Also the CFrameWnd dont have a create function with the same signature as the create function of CWnd.
nave
|
|
|
|
|
Will the assignment of m_pMainWnd not overide it being a pointer to CWnd and point to CFrameWnd. What is the explanation behind this?
|
|
|
|
|
tom groezer wrote: Will the assignment of m_pMainWnd not overide it being a pointer to CWnd and point to CFrameWnd
No. From the point of view of the compiler, it only knows m_pMainWnd is a CWnd pointer.
Assigning it a pointer to a derived class object doesn't change its type. It does change
what virtual methods get called using the base class (CWnd) pointer though
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
tom groezer wrote: it being a pointer to CWnd and point to CFrameWnd.
Even though the m_pMainWnd points to a CFrameWnd object, the CFrameWnd dont have a Create function with the same signature of CWnd::Create(). So no scope for virtual function call also
nave
|
|
|
|
|
I want to use CImage, which needs atlimage.h, but the problem is that I don't have this file on my computer (I use Visual Studio 6.0 on WinXP).
Do you know where can get the headers/libraries I need ?
|
|
|
|
|
I think you need at least Visual Studio Standard edition.
|
|
|
|
|
i am using visual studio 6.0
|
|
|
|
|
Why you didnt use of GDI+ ? anyway on the codeproject has an article I think its good for you its name is CXImage.
|
|
|
|
|
I agree with WhiteSky.
CImage uses GDI+ internally. You can use GDI+ directly. For CImage you'd need VS2003+ I believe.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I write a program to dectect a new arrival USB-FLASH DISK [U-DISK]! if this arrival U-DISK satify my condition ,I do nothing and let it work defaultly; otherwise, I call a function to disable this arrival U-DISK.
my solution is :
1. write a function to disable specified U-DISK;
2. write a function to judge wheather the arriaval U-DISK is I wantted;
3. realize WM_DEVICECHANGE event and in this event to call my function;
the functions above may work correctly; but when I add WM_DEVICECHANGE event, these function work unuseful.I just want to know:Can I disable a specified U-DISK in WM_DEVICECHANGE?
there cannot upload sample codes.if someone may solve this problem or have interest with it ,please contact me and I will give you my sample codes.
thanks a lot .
|
|
|
|