Forum: C++ Aug 30th, 2008 |
| Replies: 1 Views: 1,570 That's how a stack works, it's a "last-in, first-out" structure. The item at the top will always be the last item that was pushed:
#include <iostream>
#include <stack>
int main()
{
using... |
Forum: C++ Aug 22nd, 2008 |
| Replies: 3 Views: 1,664 The only thing Edward can think of is using a union like that isn't required to work even if the conversion is safe but a reinterpret_cast<> is. The rules say that assigning to one member of a union... |
Forum: C++ Aug 22nd, 2008 |
| Replies: 5 Views: 606 Sorry, Edward was accidentally using a Visual Studio extension. This should work:
#include <iostream>
#include <string>
class Field{
public:
virtual void display() = 0;
virtual int... |
Forum: C++ Aug 22nd, 2008 |
| Replies: 5 Views: 606 // Star is in the wrong place
void Field::*data(){
return NULL;
}
// Star is in the wrong place
// void* is the wrong return type
void Field::*clone() const{
return NULL;
} |
Forum: C Aug 19th, 2008 |
| Replies: 3 Views: 1,533 strtok ignores empty fields. Edward would recommend using another solution, like strcspn and some method of reading or copying a substring:
#include <stdio.h>
#include <string.h>
int main()
{... |
Forum: C++ Aug 19th, 2008 |
| Replies: 10 Views: 1,262 Sorry for not being clear. |
Forum: C++ Aug 18th, 2008 |
| Replies: 10 Views: 1,262 That's another way of saying the same thing. :) |
Forum: C++ Aug 18th, 2008 |
| Replies: 4 Views: 653 One of Ed's favorite books is Inside the C++ Object Model (http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545). You're asking for a lot of hardcore low level info, and I doubt... |
Forum: C++ Aug 18th, 2008 |
| Replies: 2 Views: 378 The starting form is the first form that's opened. If you're using code generated by the new project wizard there will be a *.cpp file named the same as your project. That's where main() is, and in... |
Forum: C++ Aug 18th, 2008 |
| Replies: 15 Views: 1,120 A good comparison will use a dynamic array using new and delete, and resize() or the size constructor for the vector to set the size initially just like the array. A good test will also use... |
Forum: C++ Aug 18th, 2008 |
| Replies: 15 Views: 1,120 How are you retrieving them? Is it in linear order or some kind of search? A straight traversal from beginning to end or end to beginning is well suited for an array, but you probably won't see a big... |
Forum: C++ Aug 18th, 2008 |
| Replies: 18 Views: 1,265 Don't think that way. Think about how much you've learned through all of the troubleshooting. :) |
Forum: C++ Aug 18th, 2008 |
| Replies: 2 Views: 376 That looks like a fun little program. :) To make it do both addition and subtraction, you need to determine what changes between the two paths. Edward sees that you need to display a different... |
Forum: C++ Aug 18th, 2008 |
| Replies: 5 Views: 2,315 If you use the same expression more than once, you should consider caching it into a variable. |
Forum: C++ Aug 18th, 2008 |
| Replies: 10 Views: 1,262 No, but that's Edward's fault for not being detailed enough. What you're doing with put() and get() is exactly what write() and read() do, and it has the same problems. By manually deconstructing and... |
Forum: C++ Aug 17th, 2008 |
| Replies: 18 Views: 1,265 It looks a lot like you're either using a really old C++ compiler, or you're compiling your code as C instead of C++. |
Forum: C++ Aug 17th, 2008 |
| Replies: 18 Views: 1,265 Try using the fully qualified name to make sure you've made the namespace visible for the <string> header:
std::string q; |
Forum: C++ Aug 17th, 2008 |
| Replies: 10 Views: 1,262 Edward's rule of thumb for binary I/O is that if you use read() and write(), the file is not portable. If you want portable binary I/O you need to deconstruct the object and write the bytes manually,... |
Forum: C++ Aug 17th, 2008 |
| Replies: 15 Views: 1,120 Using arrays instead of vectors only saves you the overhead of C++'s object model, especially if you need a dynamically sized array. Instead of playing memory games, try using something other than a... |
Forum: C++ Aug 17th, 2008 |
| Replies: 10 Views: 1,262 Not directly through the object by default. The easiest solution if you need that information is to pass it along with the object as a parameter. To save yourself some trouble in keeping up with... |
Forum: C++ Aug 17th, 2008 |
| Replies: 8 Views: 1,616 Edward's first guess without seeing the code is that you corrupt your memory somewhere and Vista is better at catching it with a hard failure, or you're just getting lucky on XP. But without seeing... |
Forum: C++ Aug 17th, 2008 |
| Replies: 14 Views: 1,713 This is how atoi() is used, basically.
#include <cstdlib>
#include <iostream>
int main()
{
using namespace std;
int a = atoi("10"); |
Forum: C++ Aug 17th, 2008 |
| Replies: 13 Views: 1,373 I was trying to avoid pushing your buttons by finding a compromise. But if you can't compromise, Ed doesn't feel strongly enough about the issue to make an enemy out of you.
So you're completely... |
Forum: C++ Aug 16th, 2008 |
| Replies: 13 Views: 1,373 If it's common to consider new-line a line terminator, programmers have to keep that in mind when writing code. That's all there is to the matter: it's used often, so programmers have to support it... |
Forum: C Aug 16th, 2008 |
| Replies: 2 Views: 378 break from the inner loop and then continue from the outer loop. If there's more to the body, you may need a flag or something similar:
while (condition) {
int nextIteration = 0;
while... |
Forum: C++ Aug 16th, 2008 |
| Replies: 13 Views: 1,373 Unless the last line has a newline before EOF, then there are N newlines. Counting newlines isn't a good solution to the problem because of that very inconsistency, and you can't rely on the final... |
Forum: C++ Aug 16th, 2008 |
| Replies: 13 Views: 1,373 +1 // the last line is not terminated by NL
But if the last line is terminated by NL, the count will be wrong. Sometimes it's better to be boring and conventional instead of clever and daring. ;)... |
Forum: C++ Aug 16th, 2008 |
| Replies: 2 Views: 591 To make a class act like an array you can overload the [] operator to simulate the same kind of indexing:
class myQueue {
public:
myQueue();
myQueue(const myQueue & CCqueue);
myQueue&... |
Forum: C++ Aug 16th, 2008 |
| Replies: 3 Views: 534 What are you having trouble with? |
Forum: C++ Aug 16th, 2008 |
| Replies: 14 Views: 1,713 One of your options is the stringstream family of classes. It's not the easiest way in Edward's opinion, but it's probably the best with standard C++:
#include <iostream>
#include <sstream>
... |
Forum: C Aug 15th, 2008 |
| Replies: 6 Views: 2,320 EOF doesn't have an ASCII value, it's required to be negative:
#include <stdio.h>
int main()
{
printf("%d\n", EOF);
return 0;
} |
Forum: C++ Aug 15th, 2008 |
| Replies: 3 Views: 1,407 You've probably already considered this, but file operations are notorious for being very slow. Going by what you've shown, I don't think replacing a few function calls with an I/O bound performance... |
Forum: C++ Aug 15th, 2008 |
| Replies: 3 Views: 467 #include is just a fun way of doing cut and paste. Separating code into header files shouldn't change how you use a class or make it less useful. :)
It doesn't, but using a namespace is a good... |
Forum: C++ Aug 15th, 2008 |
| Replies: 1 Views: 312 cin>>name
You're missing a semicolon to terminate the statement.
cout << end1<< "Well Hello " << name.c_str()
It's endl, with a lower case L, not end1 with the number 1. Edward would recommend... |
Forum: C++ Aug 15th, 2008 |
| Replies: 3 Views: 467 How about storing those options in a singleton:
#include <iostream>
#include <string>
namespace EdRules {
using namespace std;
class GlobalOptions {
public: |
Forum: C++ Aug 15th, 2008 |
| Replies: 14 Views: 1,713 By the looks of it, you're supposed to manually manage the numbers. Edward's first attempt would probably use strings to store the numbers and then handle the arithmetic just like it's taught in... |
Forum: C++ Aug 15th, 2008 |
| Replies: 13 Views: 2,481 If you don't mind Edward giving some constructive criticism, read on. :)
// This should never be in the global scope
using namespace std;
// Global variables should be avoided when possible... |
Forum: C++ Aug 15th, 2008 |
| Replies: 14 Views: 1,713 C++ places hard limits on the size of the built in types. If you want something larger you need to use a library that supports big numbers, like GMP (http://gmplib.org/). |
Forum: C++ Aug 15th, 2008 |
| Replies: 13 Views: 2,481 >I get a error if I don't have ; after else statement, before sum = 0
else (number < 0)
The else statement doesn't have a condition; the condition is implied by the accompanying if and else if... |
Forum: DaniWeb Community Feedback Aug 14th, 2008 |
| Replies: 24 Views: 2,502 According to the rules, you can't post anything related to pirated programs. Edward would assume that includes linking to sites that offer cracked software. |