|
Post by Cinnamon on Dec 8, 2011 0:38:01 GMT -5
Just got C++. I'm going to learn this mostly through tutorials, but does anyone know any basic guidelines for creating applications of sorts? Or how to give a program multiple OS compatibility?
|
|
|
Post by Dead on Dec 8, 2011 8:38:46 GMT -5
Multiple OS compatibility is easy (unless you are an idiot that uses windows specific code. the EVIL system("pause") for example, protip DON'T EVER USE system("") UNLESS YOU HAVE A VERY GOOD REASON TO!
for printing on the screen use printf() it is x-platform.
second. guidelines, I assume you want to know how to structure your code....
here's the preffered way:
//comment here
int main (void)
if function()
{ sum code; }
m0ar code
/* really long comment here */
if (i==1); {
if(lolz==0) return 1;
else {
lolz; tis is; code;
} }
return 0;
and don't try to conserve blank lines, they're cheap and make the code easier to read.
always comment your code so you can easily remember what a function does without studying it.
and third.
plase the semi-colons (probably misspelled it....., you know one of these ';' ) ON THE SAME LINE THAT YOU FINISH THE STATEMENT! WRONG
statement() ;another statement() [img]http://i130.photobucket.com/albums/p264/bryanthesnotskie/emoticons/pirate.png[/img]/code] RIGHT [code] Statement(); another statement()[img]http://i130.photobucket.com/albums/p264/bryanthesnotskie/emoticons/pirate.png[/img]/code]
and lastly, the compiler doesn't care about whitespaces, humans do... WRONG [code]intmain()statement();anotherStatement();if(hello.world=true){youarep0wned;}return 0; it will compile, but it is virtually impossible to read
RIGHT
int main()
statement(); anotherStatement();
if(hello.world=true) { youarep0wned; } return 0;
as you can see this is easier to read.
|
|
|
Post by Cinnamon on Dec 8, 2011 10:41:03 GMT -5
awesome, thanks! btw Windows is not evil -.- well thanks for the infos, I'll try to memorize it (must become second nature or I just CAN'T do it) I tried to make a "Hello World!" program. It worked, but it closes the instant it opens.
|
|
|
Post by Dead on Dec 8, 2011 16:52:16 GMT -5
awesome, thanks! btw Windows is not evil -.- well thanks for the infos, I'll try to memorize it (must become second nature or I just CAN'T do it) I tried to make a "Hello World!" program. It worked, but it closes the instant it opens. please read again... you will find that I said system("pause") is evil. not windows. I could link you to an article saying why system("pause") is evil... it also explains why not to use system("") at all.... and third, A7ex, system("pause") is probably what you are thinking about, there are alternatives. google " Alternatives to system("pause") " and you will find answers. (I am not going to answer everything, especially things that could easily be googled.)
|
|
|
Post by Cinnamon on Dec 8, 2011 17:39:26 GMT -5
okay, thanks! I'll check it out later Quick Q: I'm using Microsoft Visual C++ 2010 Express, is there anything Professional has that's better than Express, besides more templates (which are useless to me)
|
|
|
Post by Dead on Dec 9, 2011 7:15:16 GMT -5
I'd use gcc and Code::Blocks <---personal preference! and btw, VC complains about printf() (says it's unsafe, hell no. they just want people to develop using windows specific c++) <----I'd change. you do know that everyone would need the correct VC++ distributable to run the application, with code::blocks and gcc (it is really the compiler that is the important part here, though VC doesn't allow custom compilers..... so use Code::Blocks and install MinGW (windoze port of gcc) then select The GNU C++ compiler and not MSVC!)
MSVC express vs pro. express is free, never used pro. I'd use Code::Blocks. <---I recommend it as well!
|
|
|
Post by Dead on Dec 9, 2011 9:56:00 GMT -5
yes.
but gcc is the best <----personal views! Others think differently!
|
|
|
Post by Cinnamon on Dec 9, 2011 17:15:11 GMT -5
MVS, it took a long time to download, I'm not trashing it
|
|
|
Post by Dead on Dec 9, 2011 17:35:41 GMT -5
**sigh** All about download times, eh? Then live with the flaws. (though I give the debugger a thumbs up it is exellent!)
|
|
|
Post by Cinnamon on Dec 10, 2011 0:53:45 GMT -5
yayz
|
|
|
Post by Dead on Dec 10, 2011 8:43:11 GMT -5
tell us your results made anything interesting yet?
|
|
|
Post by Cinnamon on Dec 10, 2011 13:54:54 GMT -5
not yet, I'm not going to learn and try a bunch of stuff all at once
|
|