🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ question

Started by
16 comments, last by fleabay 3 years, 5 months ago

It is difficult to remember what you must to return 0 or 1. Return EXIT_SUCCESS or EXIT_FAILURE. This macros contains 0 and 1 respectively.

#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;

    bool isError = false;
    if (isError)
    {
        std::cerr << "Error message" << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Advertisement

I think it is right for Qt console application, isn't it?

#include <QCoreApplication>
#include <iostream>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    std::cout << "Hello World!" << std::endl;

    bool isError = true;
    if (isError)
    {
        std::cerr << "Error message" << std::endl;
        return EXIT_FAILURE;
    }

    return a.exec();
}

In DOS the return value can be used to let the system or other batch scipts know that the program completed succesfully or encounterd an error. You or someone else can use this to handle acordingly:

See for reference:
https://www.tutorialspoint.com/batch_script/batch_script_return_code.htm

None

Bazzy_505 said:
void myAwesmeFunction() { // your code };

Please be careful here. This is not a complete function, as the closing curly bracket is comment text. Either use 2 lines, or a block comment like

void may_awesome_function() { /* your code */ }; // C++ typically doesn't use camelcase for functions.

Prototype said:
There even was a YESNO.COM that would ask for user input and more of that. It was more or less an attempt at modular programming.

I think they tried to simulate a Unix shell, except it failed horribly as the COMMAND program was too weak compared to a Unix shell, and lack of multi-tasking pretty much broke any attempt to use pipes.

Alberth said:
C++ typically doesn't use camelcase for functions.

Yes it does. Why would you say that, even as part of an example comment?

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement