|
Suppose there is a class ClassTest with one argument constructor (no default constructor).
ClassTest
{
Public:
ClassTest(int i); //no default Cotr
}
A non heap array of objects of above class can be created as below
int ID1, ID2, ID3;
ClassTest ArrayClassTest [] = { ID1, ID2, ID3};
How to create an array of object of class ClassTest. If its Ctor takes two args
ClassTest
{
Public:
ClassTest(int i,int j); //no default Cotr
}
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
vibindia wrote: int ID1, ID2, ID3;
ClassTest ArrayClassTest [] = { ID1, ID2, ID3};
How to create an array of object of class ClassTest. If its Ctor takes two args
ClassTest
{
Public:
ClassTest(int i,int j); //no default Cotr
}
ClassTest ArrayClassTest [] = {ClassTest( 1, 2), ClassTest( 1, 2)};
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I used StringFormatFlagsDirectionVertical , but it is 90 degrees clockwise.
How to draw a string 90 degrees counter clockwise?
Thanks.
|
|
|
|
|
Matrix matrix;
matrix.RotateAt(/*stuff*/);
graphics.SetTransform(&matrix);
graphics.DrawString(/*stuff*/);
graphics.ResetTransform();
|
|
|
|
|
90 counter clockwise = 270 clockwise
Judy
|
|
|
|
|
Yes, it is.
But the origin is (0,0), so just rotate is not enough.
|
|
|
|
|
use the Matrix to translate, offset, scale, rotate, etc...
See my previous post in this thread.
|
|
|
|
|
Hi all,
I have a CString as follows,
CString str = "Some Data";
str.Format(_T("%s%d"), str, 123) );
If I use str as a standard string in c++, how can I do this format.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: If I use str as a standard string in c++, how can I do this format.
Use std::stringstream .
std::stringstream strstream;<br />
strstream << "Some data: " << 123;<br />
strstream.str();
CodingLover wrote: CString str = "Some Data";
str.Format(_T("%s%d"), str, 123) );
Doesn't this crash? You are passing str to str.Format function, and IMO %s doesn't know what's an object to copy it by value, so it's taking it by address. Format function will in turn modify this address to store new string!!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Thanks for the infor. I'll try this and see.
Nibu babu thomas wrote: Doesn't this crash? You are passing str to str.Format function!!
Actually I dot this from MSDN and it gives only a compile error that, addition ) at the end.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Actually I dot this from MSDN and it gives only a compile error that, addition ) at the end.
But it's clearly written in MSDN that this will cause unpredictable results. In fact given as a warning to avoid such code!
From MSDN:
The call will fail if the string object itself is offered as a
parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%s%d", str, 123);
will cause unpredictable results.
Also note this...
MSDN:
When you pass a character string as an optional argument, you must
cast it explicitly as LPCTSTR.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I agree with you. 95% of the time you can get away with it but then it fails under certain circumstances. Lots o' fun to debug after you've coded it all over the place.
Convenient? yes.
However, it will piss you off when the unpredictable results come a calling.
Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
They will live and learn someday.
|
|
|
|
|
bob16972 wrote: Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
But it's documented not to do so!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Don't get me wrong, I agree with you.
It just always confused me why people tend to shun good advice. I am always laughed at for being cautious since it tends to yield the same results as being reckless 9 times out of 10. I sometimes question whether I should just join in and throw caution to the wind, but that's just not me so I continue mind the documentation and take the safer road.
|
|
|
|
|
Ok, in such a case what should I do?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Ok, in such a case what should I do?
CString str;
str.Format("%s%d", _T( "Some Data" ), 123);
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Yes, that's right. But why I try this is, avoid CString in my application and do it using standard C++.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CString::Format() is based on sprintf() which is based on printf().
TCHAR strBuffer[ 255 ];
_stprintf( strBuffer, _T("%s%d"), _T("Some Data: "), 123 );
_sntprintf( strBuffer, 255, _T("%s%d"), _T("Some Data: "), 123 );
|
|
|
|
|
But I don't like to use buffers to this. In some cases I need to use just a byte to store data.
Anyway, thanks for the replay.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Thanks for the tip, I was using it wrongly too.
I didn't understand the explanation of that warning when I started to use the function as the OP.
Luckily I had no crash so far :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
There are multiple ways. One is as follows:
#include "stdafx.h"
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ostringstream oss;
oss << "Some data" << 123;
string s = oss.str();
cout << s << endl;
return 0;
}
Another solution (which I prefer) is to use Boost[^]'s Format[^] library as in the following example:
#include "stdafx.h"
#include <iostream>
#include <boost/format.hpp>
using namespace std;
using namespace boost;
int main()
{
cout << format("%1% %2%") % "Some Data" % 123 << endl;
return 0;
}
Steve
|
|
|
|
|
Thanks for the infor. I'm really looking into boost.
One of my friend says that using boost easy to handle command line parameters too. May be my next question on that.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hey all, was hoping you could help me with a little info here.
There's this application we use that's around 10+ years old, and I'm pretty sure it was written in C++.
There are some data files it uses with an extension of ".md" and a fileheader of "MDB2"
I was wondering if anyone's come across a database or file type like this in the past. My reasoning is, the source for the app has been lost for some time, but that's ok, the app itself runs decent enough, but we'd really like to update the data in these files if possible.
The powers that be are hoping it's a known format, but I've tried just about everything I could think of to access them.
Thanks!
|
|
|
|
|
Does anybody knows why VC6.0 decided to give me this error message everytime I set breakpoint?
I am about to go thru "standard VC6.0 recovery" - delete /debug , *.clw,
*.aps. Hope it works!
Cheers Vaclav
|
|
|
|
|
i typically see that when the breakpoint was set in a module which wasn't built in debug mode (or didn't have debug info)
|
|
|
|