Search:

Type: Posts; User: laserlight

Page 1 of 20 1 2 3 4

Search: Search took 0.16 seconds.

  1. Of course. You just need to decide on what you...

    Of course. You just need to decide on what you want the output to look like, and if you intend to read programmatically from file, you need to decide on an output format that can be read like that.
  2. Then there's no problem. You're using fwrite to...

    Then there's no problem. You're using fwrite to write a binary representation of the struct person object to file, so when you open the file as if it were a text file, you might find some unusual...
  3. Instead of: line.str(temp); Try: ...

    Instead of:

    line.str(temp);
    Try:

    istringstream line(temp);
    Note that this doesn't put the lines in the vector; it puts "words" extracted from the lines into the vector. If that's your aim...
  4. Replies
    10
    Views
    136

    ... and experience the pain of your code failing...

    ... and experience the pain of your code failing to compile because the header does not exist :p

    Or experience the pain of never having using namespace std; in your code, not even in local scopes,...
  5. I'm more interested in "straight insertion sort"....

    I'm more interested in "straight insertion sort". Canonical bubble sort is well known and quite clearly different from canonical insertion sort. The question here is whether this is an inefficient...
  6. Wait, I just realised that you wrote: "According...

    Wait, I just realised that you wrote: "According to Knuth (Vol 3) and Wikipedia the defining feature of insertion sort is that the terminating condition is when no swaps have occurred."

    That would...
  7. That's interesting: I've understood the defining...

    That's interesting: I've understood the defining feature of insertion sort as being "insert in relative position", whereas bubble sort's would be "always swap adjacent elements if out of order". That...
  8. It's legal because you know exactly what you're...

    It's legal because you know exactly what you're sorting: const void* objects. Basically, the idea is to sort pointers rather than the original int objects themselves. So, the sorted pointers will...
  9. It's bubble sort: the inner loop does repeated...

    It's bubble sort: the inner loop does repeated comparison of adjacent items and swaps them if they are out of order. The outer loop loops enough times to ensure that there are enough inner loop...
  10. That doesn't look correct to me: since arrToSort...

    That doesn't look correct to me: since arrToSort is a void*, arrToSort[i] is illegal as pointers to void cannot be dereferenced.

    By the way, it would be better not to typedef the pointer types...
  11. Poll: I agree, which is why I'm fine with overloading...

    I agree, which is why I'm fine with overloading operator<< for ostream. I'm also fine with what may be the most epic abuse of operator overloading ever: the Spirit parser framework, which tries to...
  12. I like the joke that subverts this koan to have...

    I like the joke that subverts this koan to have the Zen master slap (using one hand) the disciple who asked him to explain this koan.
  13. Well, if a newer version of the C standard...

    Well, if a newer version of the C standard introduces stuff that result in a performance improvement when used in your code, sure, if you do make use of it.
  14. Poll: Not really: with the original semantics of...

    Not really: with the original semantics of operator= it looks like you're trying to replace the output stream with the object. Surely that is wrong.

    The argument that these constitute abuse of...
  15. Poll: Think "arrows", not shift operators. This is why...

    Think "arrows", not shift operators. This is why I included "abusing?" as a comment: it changes the meaning of the operators entirely.

    Of course, you did the same by using operator= to mean...
  16. Poll: Probably because Stroustrup was thinking of cout...

    Probably because Stroustrup was thinking of cout << x as sending x to output, and cin >> x as sending from input into x, so using (abusing?) the shift operators was a nice way to indicate the...
  17. Replies
    12
    Views
    149

    No, member functions defined in a template class...

    No, member functions defined in a template class definition tends to be less verbose: you don't need to keep listing the template parameters.

    Why do you need friend functions here?
  18. Replies
    12
    Views
    149

    A friend function is just a non-member function...

    A friend function is just a non-member function that has access to private members as if it were a member function.
  19. Replies
    12
    Views
    149

    You're probably thinking of how an implicit...

    You're probably thinking of how an implicit conversion could work with say, operator+

    If you have operator+ as a member, then you could write x * 2 but not 2 * x. As a non-member, you could write...
  20. Poll: Out of curiosity, but have you tested your code?

    Out of curiosity, but have you tested your code?
  21. I buy PDF copies of the standards, so I can't...

    I buy PDF copies of the standards, so I can't link you to them. Uh, it's possible I opened the wrong one: it should have been C11, but because I was in a rush, it's possible it's actually say, C++....
  22. This is why I think this kind of exercise is...

    This is why I think this kind of exercise is helpful first to reason, then to test by compiling and running the program with output to help to see if one's reasoning is correct. Of course, just...
  23. You probably just want to declare TrafficLight as...

    You probably just want to declare TrafficLight as a char here and not bother with the enum.
  24. Replies
    12
    Views
    149

    It's the same rule as any other function: if it...

    It's the same rule as any other function: if it needs (or may be critical for efficiency for it to have) access to the internals of the class, then it should be a member or a friend. Otherwise, if it...
  25. Replies
    1
    Views
    80

    Do you know how to define your own functions?...

    Do you know how to define your own functions? Personally, what I would do is to define a function for reading in the five numbers, then one function each corresponding to the first 4 menu options....
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4