|
int len=mystr.GetLength() + 1;
char* array=new char(len);
lstrcpy(array, mystr);
or
CString s( "abcd" );
LPTSTR p = s.GetBuffer( 10 );
strcpy( p, "Hello" );
s.ReleaseBuffer( );
|
|
|
|
|
CString s( "abcd" );<br />
LPTSTR p = s.GetBuffer( 10 );<br />
strcpy( p, "Hello" );
ReleaseBuffer( );
Yes, yet another bad example from MSDN! No enforcement of the buffer size obtained (should have used strncpy(...) ), and no exception handling for example.
IOW, typical high-quality MSDN documentation/examples that newer developers can learn all kinds of bad habits from!
Peace!
-=- James
Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"! Articles -- Products: Delete FXP Files & Check Favorites
|
|
|
|
|
James R. Twine wrote:
Yes, yet another bad example from MSDN!
A problem that they have acknoledged in MSDN Magazine Editors Note i believe. The site is huge with years of information built up. They are addressing the issue. Until then you can find newer resources there if you try.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/strsafe.asp[^]
James R. Twine wrote:
typical high-quality MSDN documentation/examples that newer developers can learn all kinds of bad habits from!
Please point us to the more complete more correct online resource that we should be using instead of MSDN
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
palbano wrote:
Please point us to the more complete more correct online resource that we should be using instead of MSDN
I thought that's what CP is for
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
The strsafe functions are somewhat new, coming out right after the "secure code initiative" (or whatever it was) stuff that MS was touting a few years back after the release of .Net. That is a loooong time from when much of the bad examples out there were written, so if "they are addressing the issue", it sure took a long time... Besides, that is but one of many kinds of bad examples.
palbano wrote:
Please point us to the more complete more correct online resource that we should be using instead of MSDN
No problem: Common Sense.[^] What is more "online" than your own brain? (And did you really need a pointer to that? )
-=- James
Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"! Articles -- Products: Delete FXP Files & Check Favorites
|
|
|
|
|
i try the first method ,but to my disappointed it did not run fine and pop a waring box to terminate my program
|
|
|
|
|
Try this instead:
int len=mystr.GetLength() + 1;
char* array=new char[len];
lstrcpy(array, mystr);
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Use GetBuffer() and when you're done call ReleaseBuffer(). That's the proper way to do it.
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
Unless there is no need to change the buffer, then the LPCSTR operator is the proper way.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Unless there is no need to change the buffer, then the LPCSTR operator is the proper way.
If there is no need to change the buffer, then it should be explicitly const , in which case you can perform a type-safe cast such as:
CString szString("abcd");<br />
LPCTSTR lpszStr = static_cast<LPCTSTR>(szString);
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
So what is the difference between:
LPCTSTR lpszStr = static_cast<LPCTSTR>(szString); and
LPCTSTR lpszStr = (LPCTSTR) szString;
They both appear to generate the same code. For the purpose of getting read-only access to the internal CString buffer, I'm not seeing a benefit in using static_cast over a traditional cast.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
you mean the advice above ,but i try that method all are dirty shown my UI dialog ,can you speak clearly? thx
|
|
|
|
|
vividtang wrote:
can you speak clearly?
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Let the programmer do the thinking, let the compiler do the work
You can pass a CString object to any function that expects a LPCTSTR, the compiler will extract a pointer to the CString's internal buffer so all you need to do is ...
void foo( LPCTSTR lpszBuffer )<br />
{<br />
}<br />
<br />
<br />
CString strData(_T("12345"));<br />
foo(strData);
The LPCTSTR data type is a pointer to a constant string (ansi or unicode), if you dont have UNICODE defined, LPCTSTR maps to LPCSTR which is defined as "a Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters" i.e const char *
OR, if all you want to do is to copy the CString buffer to a char[] use strcpy(), strncpy, or _tcscpy(), _tcsncpy() e.g. strcpy(MyBuffer, LPCTSTR(MyCString));
|
|
|
|
|
I have never used them, but how do you arrange for them to be displayed.
My MFC appication has one defined and I have placed some info in it, but then thought how do you display and close it?
|
|
|
|
|
huh ? what Box ? if your MFC app. defined one, maybe you can tell us more about the Box in question ?
oh, it's the "About Box" silly me ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
That's the funniest post I've seen in a while!
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Something like this:
CAboutDlg aboutDlg;
aboutDlg.DoModal();
(You may have to include its header)
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
If AppWizard created the application, then the necessary code is in place to display the About box. If it is a dialog-based app, check its system menu. If its an SDI or MDI app, check the toolbar and the Help menu option.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Can anyone help me in building a simple neural network in pure vc++. I'm trying to build a neural network for some image segmentation processes.
|
|
|
|
|
There's a lot of that going around
GOOGLE: VC++ "neural network"
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
yeah i appreciate ur suggestion.... but wht i want is a brief description of how to develop a neural netwrok in VC++, but wht i'm getting a good stuff on neural netwroks from google but not their exact implementation regarding to coding part. Hope u got my point.
|
|
|
|
|
didn't you asked already, 2, 3 times ?
Maybe nobady knows, or don't want to help or cannot divulge "exact" implementation.
Seems to me it's a hard and complex topic, and that helping you directly will mean spending a lot of time teaching you.
another good start(*) : ftp://ftp.sas.com/pub/neural/FAQ.html[^]
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I agree,
While I am no expert on the subject of neural networks I have developing a lossless compression program since May2003. I spend a minimum of 50 hours per week on it and usually closer to 100 hours per week. I have gone as far as to produce a bogus compression program that only has a 1% probability of compression. I leave it complete with source code on disk laying around in my back pack in case someone tries to steal the code while I am not looking. This could waste weeks even months of their time figuring out that it is bogus. Specialty code is prized by many of us.
I do understand that you are only looking for starting point. Your question has sparked an interest for me. I did a search at google.com on neural network and found many great sources...
http://www.cs.stir.ac.uk/~lss/NNIntro/InvSlides.html
http://ieee-nns.org/
http://www-ra.informatik.uni-tuebingen.de/SNNS/
http://www.mathworks.com/products/neuralnet/
http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.html
many many more.
I would also try searching A.I. or artificial intelligence.
Good Luck!
demasoni.com
|
|
|
|
|
pavanbabut wrote:
but not their exact implementation regarding to coding part.
Well this project, found using that same google search, provides full source code download so i don't understand what you are asking for.
http://www.amygdala.org/[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|