Is one way better than the other?
-
Hello, Just wondering if one of these ways is better than the other? And why?
char sTest[256];
lstrcpy(sTest,"testing");
CString strTest = sTest;or
CString strTest;
strTest.Format("%s",sTest);Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
Hello, Just wondering if one of these ways is better than the other? And why?
char sTest[256];
lstrcpy(sTest,"testing");
CString strTest = sTest;or
CString strTest;
strTest.Format("%s",sTest);Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!
Huh ?
CString strText("Testing");
or did I missed something ?
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
-
Huh ?
CString strText("Testing");
or did I missed something ?
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
-
Huh ?
CString strText("Testing");
or did I missed something ?
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
I was just trying to make the question simple.. I have a structure that contains chars, int's etc... I send the structure across a socket.. when it's received on the other side I I want to put the char (from the structure) into a CString. so my question was is it ok to to do a CString strTest = sTest or should I use the format function provided by CString? I guess I just tried to over simplify the question... Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
I was just trying to make the question simple.. I have a structure that contains chars, int's etc... I send the structure across a socket.. when it's received on the other side I I want to put the char (from the structure) into a CString. so my question was is it ok to to do a CString strTest = sTest or should I use the format function provided by CString? I guess I just tried to over simplify the question... Rob Whoever said nothing's impossible never tried slamming a revolving door!
The following two lines are equivalent:
std::string s1("one"); // Example 1 std::string s2 = "two"; // Example 2
If I recall correctly, there is a standard "short-cut" that compilers can (must?) take to make example 2 above work like example 1. In other words, declaration with assignment is optimised to a constructor provided that an appropriatly overloaded constructor exists. If no constructor, you get a compiler error. Either would likely be faster then default constructor followed byFormat()
for two reasons. First, it's two steps. Second,Format()
is probably slow with all that string parsing. Of course, YMMV. Brad -
The following two lines are equivalent:
std::string s1("one"); // Example 1 std::string s2 = "two"; // Example 2
If I recall correctly, there is a standard "short-cut" that compilers can (must?) take to make example 2 above work like example 1. In other words, declaration with assignment is optimised to a constructor provided that an appropriatly overloaded constructor exists. If no constructor, you get a compiler error. Either would likely be faster then default constructor followed byFormat()
for two reasons. First, it's two steps. Second,Format()
is probably slow with all that string parsing. Of course, YMMV. Bradwill #2 generate a copy constructor ? or will it be converted into constructor ?
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
-
will #2 generate a copy constructor ? or will it be converted into constructor ?
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
std::string s1("one"); // Example 1 std::string s2 = "two"; // Example 2
Those two lines are identical. They both call a one-parameter ctor. Even though line 2 uses=
, it does not calloperator =
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated Aug 30! -
Hello, Just wondering if one of these ways is better than the other? And why?
char sTest[256];
lstrcpy(sTest,"testing");
CString strTest = sTest;or
CString strTest;
strTest.Format("%s",sTest);Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!
Format()
in this case is the worse choice of the two, because it's a bit harder to read. With the plain assignment, it's clearer what the code is doing.Format()
also will run a bit slower because it has to parse the format string and the other arguments in order to calculate the length of the resulting string, although the slowness is nothing a person would even notice. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated Aug 30! -
Thanks, your post really helps. I love it when people are nice. Whoever said nothing's impossible never tried slamming a revolving door!
-
Well, we'd rather have the stupid people making the stupid replies shut the f*ck up. Then once they become smart enough to realize that acting like an asshole is stupid, their contributions will be more than welcome to those who need help. Regards, Alvaro
Hey! It compiles! Ship it.
-
Hello, Just wondering if one of these ways is better than the other? And why?
char sTest[256];
lstrcpy(sTest,"testing");
CString strTest = sTest;or
CString strTest;
strTest.Format("%s",sTest);Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!
M. Dunn has the right response. If you are just assigning a simple string of characters to the
CString
object, using the assignment operator is the easiest. Employ the use ofFormat()
only when variables/values need to be substituted.