Ask your question in its own thread, with code, example input and expected output.
Ask your question in its own thread, with code, example input and expected output.
am I the only one that sees this as the equivalent of "Why learn long division when we have calculators?"Originally Posted by ChaosEngine
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Learn long division and how to use calculators, but use calculators (unless you need long division, or can do the calculation mentally or on paper).am I the only one that sees this as the equivalent of "Why learn long division when we have calculators?"
Learn dynamic arrays with new[]/delete[] and how to use vectors and other containers, but use vectors and other containers (unless you need dynamic arrays due to some exceptional reason).
I think the reason why it is good to learn both is that abstractions leak, but as long they dont, it makes more sense to use the abstraction.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Work out the following to as many decimal places as you can:Originally Posted by major_small
123.45/234.567
645647.654/4353
Are you seriously telling me you're going to sit down and work them out by hand or are you going to use the tools available to you?
Of course you should learn and understand long division, but to suggest that you shouldn't automate it is just plain stupid.
We're computer programmers!!! The whole point of writing computer programs is to automate tasks, that are boring/error-prone/slow. Yet for some reason C/C++ programmers have this insane irrational fear that anything in a library must be inefficient. This is why people who write in other languages laugh at C/C++ programmers. This is why a script kiddie writing in c# can produce code faster than a typical C++ programmer with 3 or 4 years experience.
If you are writing code professionally, you better have a damn good reason for using a dynamic array over a vector, otherwise you are wasting your employers time/money.
Sorry, but this issue really annoys me.
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
About the only use for hand written arrays in C++ is when you have to communicate with older C libraries. for instance windows API
char *text = new char[128];
GetWindowText(hwnd, text, 128);
delete[] text;
other than that, best to use std::vector. The optimization argument can easily be wrong too these days, because inlining and the vector template fitting better into the C++ libraries can make vectors faster than C style arrays.
Actually, you can and should use vector in that instance as well:Code:vector<char> text(128); GetWindowText(hwnd, &text[0], 128); // no delete necessary
ow maybe you can give the definitive answer then. We had a discussion once if you could do this. It comes across kinda hackish because access to the internal mechanism of vector is given. But this would be perfectly safe?Originally Posted by Daved
You couldnt do this with std::string for example because the length of the string wont necessarily be updated so you'd better do
std::string text = buf; and then delete buf after the call to GetWindowText
This is one instance where the internal representation is guaranteed by the standard, and it is done just for this purpose. In the 1998 standard it was somewhat ambiguous, but they corrected that recently and all major standard library implementations follow the practice anyway. The vector must hold its contents in contiguous memory, so that &v[0] can be used for backwards compatibility with functions taking C style arrays.
You couldn't do this with std::string because it's memory isn't guaranteed to be contiguous. The issue isn't with the length not being updated, because the length of the vector or the length of the character array aren't updated either. It is just that GetWindowText expects a contiguous array of modifiable characters that std::string cannot provide.
I would use vector, and then assign &v[0] to the string (since that would be the first character of a null terminated string). Using a local buffer is also fine, but I wouldn't use new[]/delete[] in this instance since the dynamic allocation is unnecessary.