Results 1 to 8 of 8

Thread: Couple C++ Questions

  1. #1

    Thread Starter
    Lively Member Algar's Avatar
    Join Date
    Jun 2003
    Location
    A place that never existed
    Posts
    127

    Couple C++ Questions

    1) How do I make for-next loops?
    2) How do I make Do-Loop loops?
    3) On Do-Loop loops, do I need a certain thing like DoEvents?
    4) What's the InStr of C++?
    5) What's the Split of C++?
    6) How do I connect to something in winsock and get data from winsock in C++?
    7) Where can I learn OpenGL in C++?

    Thanks for your help as I have started C++ like yesterday.
    www.hotvbforum.com for some great VB and C++ forums!

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    if you started yesterday forget about 6 and 7 for quite some time...otherwise www.cprogramming.com has some good tutorials

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Considering 3, there's no such thing as DoEvents in C++.
    C++ is not a graphical language. It's multipurpose. VB is designed for a graphical windowing system and an event-based architecture. C++ is not designed for anything.
    Given that there are no events in C++ itself, there of course is no DoEvents in C++.
    In addition, most programs you will create in your early days will be console programs, which shut you off from the quite complicated windows programming environment. Console programs don't have events, so there is no need for anything like it.
    When you proceed to windows programming you'll encounter events. You will response to those events with code.
    BUT: DoEvents in VB is just a poor remedy for the lack of threads. In C++ you can use multithreading, which is far superior to DoEvents. This, however, is a quite advanced concept.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Lively Member Algar's Avatar
    Join Date
    Jun 2003
    Location
    A place that never existed
    Posts
    127
    OK I'm learning from cprogramming.com. I have a question. Undefined integers start in the negative millions right?
    www.hotvbforum.com for some great VB and C++ forums!

  5. #5
    Lively Member
    Join Date
    Aug 2002
    Posts
    78
    Failure to initiliaze will start you in the negative millions sometimes...

    Just initialize all your variables and it won't happen.

    Because 'Strings' don't exist exactly in C++ but are a actually classes Split doesn't exist however there are many good string.h classes with the Tokenize function which basically is the same thing.

    As for the for loops...I suggest use while loops as they are easier to use and understand. Also for loops change from compiler to compiler so they really are just a bad choice until your certain you will be using compiler X for all time or know how to convert them correctly.

    while(conditions)
    {
    events
    }

    for(type var_name; condition; incrementation)
    {
    events
    }
    Last edited by Balron; Jul 11th, 2003 at 01:08 PM.
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  6. #6

    Thread Starter
    Lively Member Algar's Avatar
    Join Date
    Jun 2003
    Location
    A place that never existed
    Posts
    127
    1 more question, how can I get the UBound of a char array?
    www.hotvbforum.com for some great VB and C++ forums!

  7. #7
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    1 more question, how can I get the UBound of a char array?
    You can't (unless it is created as a local variable, but usually it is not). That's why it's better to use std::string for strings and std::vector for other arrays. both have a .size() member, which you can use to determine their size.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Please ignore what Balron said.

    Just initialize all your variables and it won't happen.
    That's a waste. You must at one point assign a value to a variable before you can use it otherwise, but that doesn't mean you must initialize every single one.
    It really depends on the situation.

    Because 'Strings' don't exist exactly in C++ but are a actually classes Split doesn't exist however there are many good string.h classes with the Tokenize function which basically is the same thing.
    ???
    string.h is in C++ a deprecated header that doesn't contain any class. string.h is superseded by cstring. The std::string class is declared in string.
    For Split, search this forum for split_string or go to www.boost.org and get their boost::string_tokenizer class.

    As for the for loops...I suggest use while loops as they are easier to use and understand. Also for loops change from compiler to compiler so they really are just a bad choice until your certain you will be using compiler X for all time or know how to convert them correctly.
    While loops are not as powerful as for loops. Use each where it makes sense. The "change" from compiler to compiler is a minor one and easily avoided.

    Here's how while and for loops really work:
    Code:
    while(expression)
    {
      statements
    }
    
    Execution:
    start the loop
    if expression is false stop looping
    do statements
    restart loop
    Code:
    while(expression1; expression2; expression3)
    {
      statements
    }
    
    Execution:
    evaluate expression1
    start the loop
    if expression2 is false stop looping
    do statements
    evaluate expression3
    restart loop

    If you want the length of a C-style string use strlen.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width