Jump to content


learning about C++


23 replies to this topic

#1 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 06:23 PM

i got to ask something

i am useing the bloodshed Dev C++ compiler and i just thought would give it a go i like to learn and try things out at certain points while i am learning it works the best for me.

now this is my question i tried a few things it did not work out then i tried this out

// myfrist.cpp this is for me learning C++

#include <iostream>
int main()
{
using namespace std;
"just seeing how this works";
"i hope this works";
}

all i was doing was experimenting of what i was reading so far the Dev C++ compiler liked that very much and compiled what i am wanting to know is Dev C++ a good idea choice to learn C++?

to be rather honest i like it very much because of its ability to give feed back but i am not sure if it is the right C++ compiler that works at a professional level.

#2 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 16 March 2009 - 06:49 PM

Use visual studio. The express edition is totally free and great.

You won't find a better IDE for C++ than visual studio.
  • www.mattiasgustavsson.com - My blog and current projects
  • www.rivtind.com - My Fantasy world and isometric RPG engine
  • www.pixieuniversity.com - My Software 2D Game Engine

#3 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 188 posts

Posted 16 March 2009 - 07:43 PM

Dev-C++ IDE is free, it works fine. I don't believe it is supported anymore, but there aren't really any bugs (that I'm aware of).

#include <iostream>

using namespace std;


int main() {


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

    printf("How are you?");


    cin.get(); /* Keep the execution window open */

    return 0;

}

Is a perfectly fine working example of a C++ program (compiles fine with Dev-C++).

#4 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 16 March 2009 - 07:55 PM

But why would you want to use something like Dev-C++ when there's Visual Studio? I don't get it...
  • www.mattiasgustavsson.com - My blog and current projects
  • www.rivtind.com - My Fantasy world and isometric RPG engine
  • www.pixieuniversity.com - My Software 2D Game Engine

#5 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 07:57 PM

this is my goals atm

1. is to code the right effective way so that i don't create bugs i feel if i can code it the right way the first time hopefully i will not have to fix a bug later.

2. to do proper codeing or scripting so i don't have to deal with bugs and if i do got to deal with them i am hopeing it is something minor.

3. and i want to move forward not to redo something over and over again.

#6 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 07:58 PM

Mattias Gustavsson said:

But why would you want to use something like Dev-C++ when there's Visual Studio? I don't get it...
i was told by buddies it was not a bad one i did not know there was better out there.

#7 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 08:05 PM

Hyper said:

Dev-C++ IDE is free, it works fine. I don't believe it is supported anymore, but there aren't really any bugs (that I'm aware of).

#include <iostream>

using namespace std;


int main() {


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

    printf("How are you?");


    cin.get(); /* Keep the execution window open */

    return 0;

}

Is a perfectly fine working example of a C++ program (compiles fine with Dev-C++).
i have not fully under stand how the return funcation works, the cout, the <<, end1;, printf, when to add (), the cin.get(),// still reading a lot of other things the book is covering.

#8 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 188 posts

Posted 16 March 2009 - 08:38 PM

cout (pronounced "see out") is the C++ standard way of outputting to the terminal (monitor, in a console).
printf is the C standard way of outputting it.

You can use: cin.get, system("PAUSE") and a few other methods to hold the execution window open (like "getch()" from conio.h).

Have fun on reading C++. If you want some inspiration (fun dinky projects that are ASCII art) I'd be glad to give you them (or post).

#9 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 08:42 PM

Hyper said:

cout (pronounced "see out") is the C++ standard way of outputting to the terminal (monitor, in a console).
printf is the C standard way of outputting it.

You can use: cin.get, system("PAUSE") and a few other methods to hold the execution window open (like "getch()" from conio.h).

Have fun on reading C++. If you want some inspiration (fun dinky projects that are ASCII art) I'd be glad to give you them (or post).
ty i appreciate the help am i right in assuming there is more then one way of codeing or scripting style that does all the same functions or is there just a limited amount of ways to do it?

#10 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 March 2009 - 08:45 PM

Mattias Gustavsson said:

But why would you want to use something like Dev-C++ when there's Visual Studio? I don't get it...
ok downloaded Visual Studio 2008 express installed it and now it is updateing going to see what it all does.

#11 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2258 posts

Posted 17 March 2009 - 04:53 AM

bazso said:

this is my goals atm

1. is to code the right effective way so that i don't create bugs i feel if i can code it the right way the first time hopefully i will not have to fix a bug later.

2. to do proper codeing or scripting so i don't have to deal with bugs and if i do got to deal with them i am hopeing it is something minor.

3. and i want to move forward not to redo something over and over again.


Note, Ive only completed a few things, I finished a music program and a few 3d modellers, but some of my projects didnt get off the floor!

1.
Coding without bugs takes practice, i still am totally killed by them all the time, all im trying to make is decent 3d graphics. And ive been doing it for
7 years now, and debugging is still of ultimate importance.

2. Theres lots of different ways to write a game, and you should pick the way that suits you. The games code structure is of utmost importance, especially when the games get more professional and theres more game system to deal with.

Games like ping pong and space invaders dont really have a structure, but real games do, and you can get yourself screwed halfway into coding it.

3. good coding practice means writing less lines that do the same job, if you need the same piece of code twice, stick it in a function and dont rewrite it.
theres other ways around not repeating code too, repeating code is complete useless code, avoid it at all costs.


But in the end, all you need is an end product, it doesnt matter how you got there, even if you coded most of it out of your head at the time.

But work it out yourself, youll probably end up better than me. im useless...

#12 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 17 March 2009 - 02:06 PM

ty so very much for the advice i am going to use the advice very much

to be honest this is my feeling we are all good at something even if it might be consider by others trivial or insignificant still we all are good at something.

#13 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 17 March 2009 - 03:19 PM

is there a book out there on the market that would explain what each function does what does it do in C++ kind of like a dictionary.

i think half my problems is i am not under standing which each function does and what it does so i don't know what to code or script.

#14 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 188 posts

Posted 17 March 2009 - 09:16 PM

bazso said:

ty i appreciate the help am i right in assuming there is more then one way of codeing or scripting style that does all the same functions or is there just a limited amount of ways to do it?

There's a limitless number of ways you could mathmatically get the number 1.
There's a "limitless" number of ways you could doing anything with a program. If there is a limit, I dare you to find it. ;)

Here's that inspiration I promised:
#include <iostream>

#include <windows.h>

using namespace std;


enum {

    BLACK       = 0,

    DARK_BLUE   = 1,

    DARK_GREEN  = 2,

    TEAL        = 3,

    DARK_RED    = 4,

    DARK_PURPLE = 5,

    GOLD        = 6,

    GREY        = 7,

    DARK_WHITE  = 8,

    BLUE        = 9,

    GREEN       = 10,

    CYAN        = 11,

    RED         = 12,

    PURPLE      = 13,

    YELLOW      = 14,

    WHITE       = 15

};


void SetColor(const int foreground) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hConsole, foreground);


    return;

}


void SetColor(const int foreground, const int background) {


    int Color = foreground + (background * 16);

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hConsole, Color);


    return;

}


void ClearConsole(const int foreground, const int background) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);


    COORD coordScreen = { 0, 0 };

    DWORD cCharsWritten;

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    DWORD dwConSize;


    if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }

    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;


    SetColor(foreground, background);

    if (!FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten)) { return; }

    if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }

    if (!FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten)) { return; }


    return;

}


void RemoveCursor() {


    /* Remove the cursor (does not work in full screen) */

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_CURSOR_INFO CursoInfo;

    CursoInfo.dwSize = 1;         /* The size of caret */

    CursoInfo.bVisible = false;   /* Caret is visible? */

    SetConsoleCursorInfo(hConsole, &CursoInfo);


    return;

}


void PlaceCursor(const int x, const int y) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);


    COORD PlaceCursorHere;

    PlaceCursorHere.X = x;

    PlaceCursorHere.Y = y;


    SetConsoleCursorPosition(hConsole, PlaceCursorHere);

    return;

}


/* Timers & Wait periods & Players */

long start[25];

long Timer[25];

int LeftWall[25] = {0};

int RightWall[25] = {0};


void Bridge() {


    bool bDraw = true;


    while (bDraw) {

        for (int x = 0; x < 25; x++) {

            if (GetTickCount() - start[x] >= Timer[x]) {

                start[x] = GetTickCount();


                if (LeftWall[x] < 40) {

                    PlaceCursor(LeftWall[x], x);

                    SetColor(RED);

                    printf("#");

                    LeftWall[x]++;

                }


                if (RightWall[x] > 39) {

                    PlaceCursor(RightWall[x], x);

                    SetColor(BLUE);

                    printf("#");

                    RightWall[x]--;

                }

            }

        }


        if (LeftWall[24] == 40) { bDraw = false; }

    }


    return;

}


void ReverseBridge() {


    SetColor(BLACK, BLACK);

    bool bDraw = true;


    while (bDraw) {

        for (int x = 0; x < 25; x++) {

            if (GetTickCount() - start[x] >= Timer[x]) {

                start[x] = GetTickCount();


                if (LeftWall[x] >= 0) {

                    PlaceCursor(LeftWall[x], x);

                    printf(" ");

                    LeftWall[x]--;

                }


                if (RightWall[x] < 80) {

                    PlaceCursor(RightWall[x], x);

                    printf(" ");

                    RightWall[x]++;

                }

            }

        }

        

        if (LeftWall[24] == -1) { bDraw = false; }

    }


    return;

}


int main() {


    RemoveCursor();

    ClearConsole(BLACK, BLACK);


    int UpCount = 0;


    start[0] = GetTickCount();

    for (int x = 1; x < 25; x++) { start[x] = start[0]; }

    for (int x = 0; x < 25; x++) { Timer[x] = 100 + UpCount; UpCount += 20; }


    for (int x = 0; x < 25; x++) { LeftWall[x] = 0; }

    for (int x = 0; x < 25; x++) { RightWall[x] = 79; }

    Bridge();


    start[0] = GetTickCount();

    for (int x = 1; x < 25; x++) { start[x] = start[0]; }


    for (int x = 0; x < 25; x++) { LeftWall[x] = 40; }

    for (int x = 0; x < 25; x++) { RightWall[x] = 40; }

    ReverseBridge();


    cin.get();

    return 0;

}

bazso said:

is there a book out there on the market that would explain what each function does what does it do in C++ kind of like a dictionary.

i think half my problems is i am not under standing which each function does and what it does so i don't know what to code or script.

That's what google and MSDN are for. MSDN is literally a "library" of functions and full of explainations.

#15 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 19 March 2009 - 02:54 AM

Hyper said:

There's a limitless number of ways you could mathmatically get the number 1.
There's a "limitless" number of ways you could doing anything with a program. If there is a limit, I dare you to find it. ;)

Here's that inspiration I promised:
#include <iostream>

#include <windows.h>

using namespace std;


enum {

    BLACK       = 0,

    DARK_BLUE   = 1,

    DARK_GREEN  = 2,

    TEAL        = 3,

    DARK_RED    = 4,

    DARK_PURPLE = 5,

    GOLD        = 6,

    GREY        = 7,

    DARK_WHITE  = 8,

    BLUE        = 9,

    GREEN       = 10,

    CYAN        = 11,

    RED         = 12,

    PURPLE      = 13,

    YELLOW      = 14,

    WHITE       = 15

};


void SetColor(const int foreground) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hConsole, foreground);


    return;

}


void SetColor(const int foreground, const int background) {


    int Color = foreground + (background * 16);

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hConsole, Color);


    return;

}


void ClearConsole(const int foreground, const int background) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);


    COORD coordScreen = { 0, 0 };

    DWORD cCharsWritten;

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    DWORD dwConSize;


    if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }

    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;


    SetColor(foreground, background);

    if (!FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten)) { return; }

    if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }

    if (!FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten)) { return; }


    return;

}


void RemoveCursor() {


    /* Remove the cursor (does not work in full screen) */

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_CURSOR_INFO CursoInfo;

    CursoInfo.dwSize = 1;         /* The size of caret */

    CursoInfo.bVisible = false;   /* Caret is visible? */

    SetConsoleCursorInfo(hConsole, &CursoInfo);


    return;

}


void PlaceCursor(const int x, const int y) {


    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);


    COORD PlaceCursorHere;

    PlaceCursorHere.X = x;

    PlaceCursorHere.Y = y;


    SetConsoleCursorPosition(hConsole, PlaceCursorHere);

    return;

}


/* Timers & Wait periods & Players */

long start[25];

long Timer[25];

int LeftWall[25] = {0};

int RightWall[25] = {0};


void Bridge() {


    bool bDraw = true;


    while (bDraw) {

        for (int x = 0; x < 25; x++) {

            if (GetTickCount() - start[x] >= Timer[x]) {

                start[x] = GetTickCount();


                if (LeftWall[x] < 40) {

                    PlaceCursor(LeftWall[x], x);

                    SetColor(RED);

                    printf("#");

                    LeftWall[x]++;

                }


                if (RightWall[x] > 39) {

                    PlaceCursor(RightWall[x], x);

                    SetColor(BLUE);

                    printf("#");

                    RightWall[x]--;

                }

            }

        }


        if (LeftWall[24] == 40) { bDraw = false; }

    }


    return;

}


void ReverseBridge() {


    SetColor(BLACK, BLACK);

    bool bDraw = true;


    while (bDraw) {

        for (int x = 0; x < 25; x++) {

            if (GetTickCount() - start[x] >= Timer[x]) {

                start[x] = GetTickCount();


                if (LeftWall[x] >= 0) {

                    PlaceCursor(LeftWall[x], x);

                    printf(" ");

                    LeftWall[x]--;

                }


                if (RightWall[x] < 80) {

                    PlaceCursor(RightWall[x], x);

                    printf(" ");

                    RightWall[x]++;

                }

            }

        }

        

        if (LeftWall[24] == -1) { bDraw = false; }

    }


    return;

}


int main() {


    RemoveCursor();

    ClearConsole(BLACK, BLACK);


    int UpCount = 0;


    start[0] = GetTickCount();

    for (int x = 1; x < 25; x++) { start[x] = start[0]; }

    for (int x = 0; x < 25; x++) { Timer[x] = 100 + UpCount; UpCount += 20; }


    for (int x = 0; x < 25; x++) { LeftWall[x] = 0; }

    for (int x = 0; x < 25; x++) { RightWall[x] = 79; }

    Bridge();


    start[0] = GetTickCount();

    for (int x = 1; x < 25; x++) { start[x] = start[0]; }


    for (int x = 0; x < 25; x++) { LeftWall[x] = 40; }

    for (int x = 0; x < 25; x++) { RightWall[x] = 40; }

    ReverseBridge();


    cin.get();

    return 0;

}



That's what google and MSDN are for. MSDN is literally a "library" of functions and full of explainations.
coolness tya again

#16 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 188 posts

Posted 19 March 2009 - 05:12 AM

Welcome. Any opinions on how that looks? ;)

#17 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 19 March 2009 - 02:32 PM

Hyper said:

Welcome. Any opinions on how that looks? ;)
it looks intense on the typeing part i would have to say it is of graphical visual nature
it deals with the mouse pointer and from what other things that's in the script*not sure if it is one*.

it is also dealing with objects and seems that there is timer looks like when you click on a object that timer starts to count and it changes color when you click on a object *not sure about that* .

it looks like the players got to wait when a event is over when a event starts to happen and it looks like your haveing color do something.

i am sure i am wrong but that's my best guess out of the dark i got no idea to be honest.

#18 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 188 posts

Posted 19 March 2009 - 04:00 PM

You are quite wrong and I thought you would've compiled it to watch it do magic. :/ Compile it!!! :)

It doesn't deal with the mouse cursor, rather, the caret that blinks. PlaceCursor moves the caret (where it draws) to X, Y coordinates. RemoveCursor actually removes it (on true-DOS you could remove it in full screen, on DOS shells for Windows now, you can only remove it on windowed mode - Windows Vista doesn't allow a full screen DOS shell now).

There is no clicking and it changes the text color twice - Red on the left and blue on the right ("curtain"). Yes, it does wait, that's what GetTickCount() is for, it waits X milliseconds (I believe GetTickCount() works on Linux as well as Windows).

Good guesses though. ;) Should compile it (Dev-C++ compiler (Dev-C++ is the IDE, the compiler is a GCC (works on Windows/Linux)) works great).

#19 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 19 March 2009 - 08:49 PM

Hyper said:

You are quite wrong and I thought you would've compiled it to watch it do magic. :/ Compile it!!! :)

It doesn't deal with the mouse cursor, rather, the caret that blinks. PlaceCursor moves the caret (where it draws) to X, Y coordinates. RemoveCursor actually removes it (on true-DOS you could remove it in full screen, on DOS shells for Windows now, you can only remove it on windowed mode - Windows Vista doesn't allow a full screen DOS shell now).

There is no clicking and it changes the text color twice - Red on the left and blue on the right ("curtain"). Yes, it does wait, that's what GetTickCount() is for, it waits X milliseconds (I believe GetTickCount() works on Linux as well as Windows).

Good guesses though. ;) Should compile it (Dev-C++ compiler (Dev-C++ is the IDE, the compiler is a GCC (works on Windows/Linux)) works great).
well i did not know that i needed to do that and forth more you forgot to mention that
not trying to lay any blame on you.

it sounded to me you wanted me to guess what the codes does.

#20 bazso

    Valued Member

  • Members
  • PipPipPip
  • 154 posts

Posted 19 March 2009 - 08:54 PM

Hyper said:

You are quite wrong and I thought you would've compiled it to watch it do magic. :/ Compile it!!! :)

It doesn't deal with the mouse cursor, rather, the caret that blinks. PlaceCursor moves the caret (where it draws) to X, Y coordinates. RemoveCursor actually removes it (on true-DOS you could remove it in full screen, on DOS shells for Windows now, you can only remove it on windowed mode - Windows Vista doesn't allow a full screen DOS shell now).

There is no clicking and it changes the text color twice - Red on the left and blue on the right ("curtain"). Yes, it does wait, that's what GetTickCount() is for, it waits X milliseconds (I believe GetTickCount() works on Linux as well as Windows).

Good guesses though. ;) Should compile it (Dev-C++ compiler (Dev-C++ is the IDE, the compiler is a GCC (works on Windows/Linux)) works great).
is debugging another way of seeing after you code/script to see what it does? i seen a red side and a blue side and it looked very COOL!!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users