|
Since you're already using the STL vector class, why not use it's string class?
Software Zen: delete this;
|
|
|
|
|
I have tried with a string variable. It is true it can solve this problem. However, in the later part of my program I need to write each struture in vector Name_Score_Collection into a file on my hard disk. I used CFile::write() to accompolish this. CFile::write() worked fine with 'char Name[MAX_LEN]', but not with 'std::string Name'. I think this is because function write() need to know the exact size for each structure to be write out. The size of a string variable is not fixed.
|
|
|
|
|
Maybe is worth that you give a look to Serialization Topics in MSDN.
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.
|
|
|
|
|
I dont think you will get a problem there. Because, when you are going to write a structure variable into a file, you will just be saying sizeof(stObj), so what's the problem in "not knowing" the the size of the string variable. Or if you want to trim something out within a limited lenght you can always check for stdMyString.size() and do it.
:Gong: 歡迎光臨 吐 西批 :Gong:
|
|
|
|
|
Hi Cy163,
> char Name[MAX_LEN] , but not with std::string Name ...
How so?
std::string Name
Name.c_str();
...
or
std::wstring Name
Name.c_str();
...
The following works under VC6.0 also (and stays within the standard C++ library). See std::string widen() and std::wstring narrow()[^]
Jeff
std::string StringNarrow( const std::wstring& wide ) {
typedef std::ctype<wchar_t> CT;
std::string narrow;
narrow.resize( wide.length() );
CT const& ct = std::_USE(std::locale(), CT);
ct.narrow( &wide[0], &wide[0] + wide.length(), '_', &narrow[0] );
return narrow;
}
std::wstring StringWiden( const std::string& narrow ) {
typedef std::ctype<wchar_t> CT;
std::wstring wide;
wide.resize( narrow.length() );
CT const& ct = std::_USE(std::locale(), CT);
ct.widen(&narrow[0], &narrow[0] + narrow.length(), &wide[0]);
return wide;
}
|
|
|
|
|
store only a pointer, inside the structure, such as
struct stru_B {
char * lpszName;
float score;
};
then, of course, you need to deal with memory allocation/deallocation.
Alternatively include STL string or MFC CString into the struct.
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 method is problematic with CFile.read(), since sizeof(struct_B) is not fixed.
|
|
|
|
|
cy163@hotmail.com wrote: this method is problematic with CFile.read(), since sizeof(struct_B) is not fixed.
That's is inevitable because you want to save variable-lenght chunks of data. You have to store the true struct lenght too (and before storing actual struct). There are several ways to do that. Again, maybe better to give a look at Serialization of MSDN.
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.
|
|
|
|
|
Call string::size() to get the length of the string.
|
|
|
|
|
I just have a simple function to get the bounding rectangle. green color is without using the pen, red is with the pen. Why is the red rectangle so much bigger? even the green is not exactly correct.
http://img246.imageshack.us/my.php?image=testqq1.jpg[^]
void Test::DrawPreview(HDC hdc)
{
Graphics graphics(hdc);
Pen blackPen(Color(255, 0, 0, 0), 1);
Pen yellowPen(Color(255, 255, 255, 0), 20);
Pen redPen(Color(255, 255, 0, 0), 1);
Pen greenPen(Color(255, 0, 255, 0), 1);
Point pts[] = {Point(120,120),
Point(200,130),
Point(150,200),
Point(130,180)};
// Create a path that has one curve and one ellipse.
GraphicsPath path;
path.AddClosedCurve(pts, 4);
path.AddEllipse(120, 220, 100, 40);
// Draw the path with a thick yellow pen and a thin black pen.
graphics.DrawPath(&yellowPen, &path);
graphics.DrawPath(&blackPen, &path);
// Get the path's bounding rectangle.
RectF rect;
RectF rect2;
path.GetBounds(&rect, NULL, &yellowPen);
path.GetBounds(&rect2);
graphics.DrawRectangle(&redPen, rect);
graphics.DrawRectangle(&greenPen, rect2);
}
|
|
|
|
|
How much larger is the red rect?
I didn't test your code, but with the yellow pen's width at 20 the red rect should be a little
bigger.
|
|
|
|
|
I tried your code. Looks like they allow PLENTY of room for the thicker pen!
*Edit* Looks like a bug to me
|
|
|
|
|
CString m_strSpeech;
m_strSpeech = "Hi Have A Nice Day";
ISpVoice * pVoice = NULL;
if (FAILED(CoInitialize(NULL)))
{
AfxMessageBox("Error to intiliaze COM");
return;
}
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(m_strSpeech.AllocSysString(), 0, 0);
pVoice->Release();
pVoice = NULL;
}
CoUninitialize();
this above i used to play a text "Hi Have A Nice Day". Output is ok. i done this dialog no other code. I placed this one in ok Button.
while running the application the memory size is 1,6XX k. I press ok button play starts. mean while memory goes to 5,XXX and return back to 3,XXX.
why it can't come back. what's the problem. any one help me out.
thanks in advance!
Have A Nice Day!
Murali.M
|
|
|
|
|
I dont know for sure, but my guess is you need to remember the result of AllocSysString() and call SysFreeString() on it.
Luc Pattyn
|
|
|
|
|
CoInitialize() involves loading up COM and setting up various things like data structures and windows for the STA. Some of that data is process-wide and won't be freed when you call CoUninit. So really, don't worry about it
Last modified: 5hrs 34mins after originally posted --
|
|
|
|
|
thanks for your reply.
but i called CoUninitialize();
Have A Nice Day!
Murali.M
|
|
|
|
|
There is already one memory leak indicated by Luc.
You can modify your code like this,
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
BSTR bsSpeech = m_strSpeech.AllocSysString();
hr = pVoice->Speak(bsSpeech, 0, 0);
SysFreeString(bsSpeech);
pVoice->Release();
}
|
|
|
|
|
thanks prasad. I try with this one. but not. my problem of memory consumption if 1,XXX K. This is not due to String allocation.
Have A Nice Day!
Murali.M
|
|
|
|
|
in c++ we can used the cin and cout , plz tel me in VC++ what function we used.
a lot of thank 's
-- modified at 5:39 Saturday 16th December, 2006
-- modified at 5:41 Saturday 16th December, 2006
naveen padiyar
|
|
|
|
|
- On console apps keep using cin/cout (even printf/scanf are a valid option).
- On windowed apps you have to use any of the text drawing methods of MFC
(e.g. CDC::TextOut, CDC::DrawText, ... or the original GDI calls TextOut, DrawText, ... ). For fancy effects, give a look at GDI+.
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.
|
|
|
|
|
where do you need it? It differs according to your need. Btw, VC++ is not something totally different from C++. C++ is still inside VC++ . If you are making a console application using VC++, you can still use "cin,cout" if MFC (or SDK), and if you want(most probably) to get from a textbox (CEdit) ::GetWindowText(), ::SetWindowText()
:Gong: 歡迎光臨 吐 西批 :Gong:
|
|
|
|
|
To disable a menu item in an sdi app i tried
(pFrame->GetMenu)->EnableMenuItem(IDC_MY_ID,MF_GRAYED);
but it did not work. How to do this?
Thanks in advance.
KIRAN PINJARLA
|
|
|
|
|
Hi Kiran,
try this :-
pFrame->GetMenu)->EnableMenuItem(IDC_MY_ID,MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
Regards,
vinsankar
|
|
|
|
|
Thank you.
But it did not work.
KIRAN PINJARLA
|
|
|
|
|
Then try to post more info about...
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.
|
|
|
|
|