Search:

Type: Posts; User: Omnius

Page 1 of 6 1 2 3 4

Search: Search took 0.02 seconds.

  1. Replies
    10
    Views
    2,045

    If you're using C++, a better practice than...

    If you're using C++, a better practice than initialising to a default value is to defer declaring your variables until you need them, then initialise at the point of declaration.
  2. Replies
    10
    Views
    2,045

    Just to reinforce this, and the difference...

    Just to reinforce this, and the difference between local and global variables, run the following:


    #include <iostream>
    using namespace std;

    int globalInt;
    double globalDouble;

    int main()
  3. Replies
    16
    Views
    3,777

    It's worth noting that at local scope the latter...

    It's worth noting that at local scope the latter adds a name to the scope, the former doesn't.

    It's surprising how often name clashes can occur even in small programs, where a well chosen...
  4. Replies
    44
    Views
    3,710

    Re: ok

    Adding cin.get() to the end of main doesn't fix anything except for the fact that some development environments (e.g. MS VC++) keep the console window open after the program has terminated when run...
  5. Replies
    7
    Views
    1,131

    #include #include using...

    #include <iostream>
    #include <numeric>

    using namespace std;

    int main()
    {
    int myInts[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    int sum = accumulate(myInts, myInts+15, 0);
    ...
  6. Replies
    5
    Views
    2,819

    What do you mean by stone age games, exactly? You...

    What do you mean by stone age games, exactly? You can make simple games for MS Windows with animation without DirectX etc. The Sams Teach Yourself Game Programming in 24 hours book develops various...
  7. Replies
    32
    Views
    12,638

    I'd say that in the vast majority of cases I'd...

    I'd say that in the vast majority of cases I'd have to agree with you. However, there are people working with programmes where even such small gains can be important. In those cases, then, such an...
  8. Thread: class???

    by Omnius
    Replies
    13
    Views
    1,453

    I've seen others with the same problem recently...

    I've seen others with the same problem recently with 5.02. Doesn't appear to be standard compliant in this respect. Best bet is simply to drop the using directive and go back to <iostream.h> until...
  9. Replies
    21
    Views
    6,958

    I don't think the fail bit will be set in this...

    I don't think the fail bit will be set in this case. I believe the stream will still be in a good state; it will just stop extracting from cin when it encounters the first non-digit character, i.e....
  10. Replies
    32
    Views
    12,638

    Thanks Hunter2. Some of us may still have an...

    Thanks Hunter2. Some of us may still have an interest in the points discussed in the thread and don't consider it absurd to do so.

    Cheers,
    Omni.
  11. Replies
    32
    Views
    12,638

    Well, I have a book that says switch "will...

    Well, I have a book that says switch "will usually be faster than anything but the most basic if-else statement"
  12. Replies
    21
    Views
    6,958

    This line: ...

    This line:

    cin.ignore(numeric_limits<int>::max(), '\n');

    will remove everything from the stream up to the next newline. It look more complicated than it is; that's C++ syntax for you. It's...
  13. Replies
    21
    Views
    6,958

    When you enter a character instead of an integer...

    When you enter a character instead of an integer cin goes into a failed state. To recover from this you need to clear the stream flags and remove any characters left in the stream, then try again....
  14. Replies
    32
    Views
    12,638

    Re: if is faster than switch?

    It's a sweeping generalisation that serves only to confuse. Ignore it.

    By the way, can you tell us which book it was that said this, and provide a direct quote?
  15. Thread: Better way

    by Omnius
    Replies
    7
    Views
    1,159

    A quick search on Google threw up:

    A quick search on Google threw up:
  16. Thread: Better way

    by Omnius
    Replies
    7
    Views
    1,159

    Having done some initial design, you should be...

    Having done some initial design, you should be able to code and test a class in isolation before using it in your application.

    Being able to define everything in fine detail is certainly one...
  17. Thread: Passing vectors

    by Omnius
    Replies
    4
    Views
    1,199

    Strictly speaking arrays aren't passed at all....

    Strictly speaking arrays aren't passed at all. You can't actually pass an array (not directly, anyway).

    When you pass an array as a function parameter what gets passed is a pointer to the first...
  18. Replies
    18
    Views
    4,755

    You've quoted many sources, but so far not the...

    You've quoted many sources, but so far not the source that actually defines the language, the C++ standard. You even include C, which is a different language, with different behaviour.

    The effect...
  19. Replies
    18
    Views
    4,755

    The behaviour of exit() is documented in the C++...

    The behaviour of exit() is documented in the C++ standard. Any good beginners book should cover it.
  20. Replies
    18
    Views
    4,755

    In C++ the use of exit() is considered poor...

    In C++ the use of exit() is considered poor practice. Terminating the program using exit() doesn't invoke destructors for local objects. Better is to terminate with return via main() or throw an...
  21. Thread: Help plz

    by Omnius
    Replies
    13
    Views
    1,596

    Re: thx

    Check the extensive online help that comes with VC++ 6.0. It will answer this and many other basic questions.
  22. Thread: array problem

    by Omnius
    Replies
    3
    Views
    944

    If your compiler complains about size_t, include...

    If your compiler complains about size_t, include <cstddef>.
  23. Re: Easiest way to find the max value stored in an array

    Well, as you're clearly using C++, why not just use max_element from <algorithm>? That would appear to me to be the easiest way:


    #include <iostream>
    #include <algorithm>

    using namespace std;...
  24. Thread: std namespace

    by Omnius
    Replies
    8
    Views
    2,337

    And even then, of course, they're not guaranteed...

    And even then, of course, they're not guaranteed to 'work' because of the possibility of name clashes. Only a namespace prefix gives you any kind of guarantee.
  25. Thread: vc ++

    by Omnius
    Replies
    1
    Views
    957

    You need to give us more information. Post the...

    You need to give us more information. Post the exact error message you receive including the error number and text, and the code you're trying to compile.
Results 1 to 25 of 138
Page 1 of 6 1 2 3 4