[C++] Need Help Getting Started With C++?

Initiate Mage
Joined
Jul 7, 2009
Messages
3
Reaction score
0
Ok. I learning C++ at the moment by myself. ( or video tutorials)
So if you need help getting started search for a guy called antiRTFM on YouTube.
He have 70 C++ video tutorials.
He is serious and talk loud and clear.
Many people have commented "You are a legend" and "Legend :D" etc.
So hes videos are :thumbup:. Check it out guys!

- Kimxp
 
AntiRTFM videos are really great, english is not my main language but I fully understood his videos. The only down-side for me is that he repeats himself too much, but that might be great for others :P
 
AntiRTFM videos are really great, english is not my main language but I fully understood his videos. The only down-side for me is that he repeats himself too much, but that might be great for others :P
Yes. But when he repeat it he make him self clearer, and n00b's ( like me ) just love that :P
 
Code:
#include <windows.h>
#include <iostream>
#include <string>

using namespace std;
string myStrng;

int main()
{

loop1:
cout << "Which is better, video tutorials, or books?\n\n";
getline(cin, myStrng);
if (myStrng == "Video" || myStrng == "video")
{
  Beep(2750, 200);
  cout << "WRONG! Try again!\n\n"
  goto loop1;
}
else
{
 cout << "Exactly.\n\n";
}
 return 0;
}

Sorry, video tutorial's aren't really the best for learning coding languages.
:P
 
Code:
#include <windows.h>
#include <iostream>
#include <string>

using namespace std;
string myStrng;

int main()
{

loop1:
cout << "Which is better, video tutorials, or books?\n\n";
getline(cin, myStrng);
if (myStrng == "Video" || myStrng == "video")
{
  Beep(2750, 200);
  cout << "WRONG! Try again!\n\n"
  goto loop1;
}
else
{
 cout << "Exactly.\n\n";
}
 return 0;
}

Sorry, video tutorial's aren't really the best for learning coding languages.
:P

Bad style, using globals where global scope unnecessary, nonstandard main form.

:(
 
Use of goto statements is neither adviced. C++ has much better alternatives which keep your code readable.
 
Sorry, video tutorial's aren't really the best for learning coding languages.
:P

I'm sorry about how flawed your logic is...so, how do we learn how to do things in school? Dont we first watch hows it's done and than practice it?

Yeah....reading out of a book is the true fail, as you have to hold the damn thing open, which keeps your hands off the keyboard...
Dual-monitor + Video + Doing what you learn = Win.
 
Code:
#include <windows.h>
#include <iostream>
#include <string>

using namespace std;
string myStrng;

int main()
{
    bool exit = false;

    while(!exit)
    {
        cout << "Which is better, video tutorials, or books?\n\n";
        cin >> myStrng;

        if (myStrng == "Video" || myStrng == "video")
        {
             Beep(2750, 200);
             cout << "WRONG! Try again!\n\n" << endl;
        }
        else if(myStrng == "Books" || myStrng == "books")
        {
            cout << "Exactly.\n\n" << endl;
            exit = true;
        }
        else
        {
            cout << "Books or Video, try again..." << endl;
        }
    }
    return 0;
}


I've re formatted your code, and removed references to labels and goto, and to getline(),
 
I've re formatted your code, and removed references to labels and goto, and to getline(),

Still has the global, and the boolean isn't really needed.

Code:
#include <windows.h>
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    std::string input;

    while (1)
    {
        std::cout << "Which is better, video tutorials, or books?\n\n";
        std::cin >> input;    

        std::transform(input.begin(), input.end(), input.begin(), (int(*)(int)) toupper);

        if (input == "video")
        {
             Beep(2750, 200);
             std::cout << "WRONG! Try again!\n\n\n";
        }
        else if (input == "books")
        {
            std::cout << "Exactly.\n\n\n";
            return 0;
        }
        else
        {
            std::cout << "Books or video, try again...\n";
        }
    }
}

Better would be looking for the word 'video' or 'book' in the input string, then an exact match. People could write 'video tutorials' instead etc.
 
Lol this became a discussion over who's code is better. It was supposed to be help for him not an argument xD.

What exactly is wrong with global variables? I use them and know alot of other people who use them too.
 
Lol this became a discussion over who's code is better. It was supposed to be help for him not an argument xD.

What exactly is wrong with global variables? I use them and know alot of other people who use them too.

A global variable is non-scoped (err, scoped to the life of your executable). So, even if you just need it in one function, it is allocated all the time. It also takes slightly more time to use IIRC. But the biggest concern is that it leads to VERY BAD coding habits. If you don't scope your variables, your way of thinking is not correct. To be a successful programmer your way of thinking is essential. Also, global variables makes your coding non-reentrant...aka, multi-threading no-no.

Many people consider global variables being bugs too. I occasionally use one for logging or error handling, since I do this globally...but it's not the neatest design and might think of something better...(I hate error handling :()
 
A global variable is non-scoped (err, scoped to the life of your executable). So, even if you just need it in one function, it is allocated all the time. It also takes slightly more time to use IIRC. But the biggest concern is that it leads to VERY BAD coding habits. If you don't scope your variables, your way of thinking is not correct. To be a successful programmer your way of thinking is essential. Also, global variables makes your coding non-reentrant...aka, multi-threading no-no.

Many people consider global variables being bugs too. I occasionally use one for logging or error handling, since I do this globally...but it's not the neatest design and might think of something better...(I hate error handling :()

"allocated all the time"
means it's stored in the .data or .rdata section of the produced executable image file, bloating the executable (not by much, but if it's course of habit and you do this with VERY large structures or arrays, it will make it rather large)

"it also takes slightly more time to use IIRC"
Not really. The access time should be identical or a difference of 1-2 cycles. It's a ds:[addr] where a stack allocated variable would be ss:[esp+var_offset].

"global variables make your coding non-reentrant"
Not quite. If the global variables are read-only, or if they're protected by some kind of threading synchronization, it's OK, but it's still considered bad style to have globals. I think people generally give leeway to things like factories and/or a debugging class because in MOST cases, in good code, debugging primitives are only compiled in when a switch is set like #define DEBUG_LEVEL or something, and so modifying classes individually to store a reference to a debugging class results in a lot of:

#if DEBUG_LEVEL > xxx
MyDebug dbg;
#endif

and so on and so forth in your code, whereas you can have something like

#if DEBUG_LEVEL > xxx
#define DEBUG_PRINT(x) MyDebug::GetInstance()->print(x);
#else
#define DEBUG_PRINT(x)
#endif

Cheers.
 
Back