User forums > General (but related to Code::Blocks)

Sugesstion about small changes in standard cpp code.

<< < (3/6) > >>

sethjackson:
The only problem with using console_runner is that if the user runs the executeble outside of Code::Blocks it will immediatly close and the user won't be able to see the output.

Here is my suggestion.


--- Code: ---#include <iostream>

int main(int argc, char *argv[])
{
    std::cout << "Hello world!";
    std::cout << std::endl;
    std::cout << "Press ENTER to continue.";
    std::cout << std::endl;

    std::cin.get();
   
    return 0;
}

--- End code ---

There is a drawback with this however if you run this code from Code::Blocks you have to press enter twice to "exit" the program.
I'm not saying the template needs to be changed but this is just my take on things. One question how come main is


--- Code: ---int main()

--- End code ---

instead of


--- Code: ---int main(int argc, char *argv[])

--- End code ---

grv575:

--- Quote from: sethjackson on September 12, 2005, 03:22:03 am ---
--- Code: ---    std::cin.get();

--- End code ---

--- End quote ---

But I think the point was that if people are writing in a unix style, with multiple processes/utilities and piped communication, then programs should just exit and provide an exit status code.  Which is what's likeable about the console_runner approach (it permits both convenience within CB and process integration w/ pipes or whatever).

It's not too bad to open cmd.exe and drag and drop the .exe from Explorer.

thomas:

--- Quote from: grv575 on September 12, 2005, 03:37:26 am ---But I think the point was that if people are writing in a unix style, with multiple processes/utilities and piped communication, then programs should just exit and provide an exit status code.  Which is what's likeable about the console_runner approach (it permits both convenience within CB and process integration w/ pipes or whatever).
It's not too bad to open cmd.exe and drag and drop the .exe from Explorer.
--- End quote ---
That is exactly it. :)
A program that blocks at the end of execution takes away the user's freedom of choice and, too, limits itself unnecessarily by being unable to be run non-interactively.

Apart from that, I think that is also an important point in ideology. Software is to serve the human, not to dictate him. Unluckily, most of the current "maintream" software does not respect that because it is too self-important. Think of even such simple a thing as an installer, or think of your antivirus software, or download a file with IE, and you know what I mean.

takeshimiya:
If it'll have to be changed, I would change it

from:

--- Code: ---#include <iostream>

int main()
{
   std::cout << "Hello world!" << std::endl;
   return 0;
}

--- End code ---

to something like:

--- Code: ---#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   cout << "Hello world!" << endl;
   return 0;
}

--- End code ---

phlox81:
Makes the "using namespace std;" really sense there ?
I feel with std:: much better. And if, it should belong _in_ the main-function.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version