learning about C++
#1
Posted 16 March 2009 - 06:23 PM
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
Posted 16 March 2009 - 06:49 PM
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
Posted 16 March 2009 - 07:43 PM
#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
Posted 16 March 2009 - 07:55 PM
- 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
Posted 16 March 2009 - 07:57 PM
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
Posted 16 March 2009 - 07:58 PM
Mattias Gustavsson said:
#7
Posted 16 March 2009 - 08:05 PM
Hyper said:
#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++).
#8
Posted 16 March 2009 - 08:38 PM
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
Posted 16 March 2009 - 08:42 PM
Hyper said:
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).
#10
Posted 16 March 2009 - 08:45 PM
Mattias Gustavsson said:
#11
Posted 17 March 2009 - 04:53 AM
bazso said:
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
Posted 17 March 2009 - 02:06 PM
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
Posted 17 March 2009 - 03:19 PM
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
Posted 17 March 2009 - 09:16 PM
bazso 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;
}
bazso said:
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
Posted 19 March 2009 - 02:54 AM
Hyper said:
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.
#16
Posted 19 March 2009 - 05:12 AM
#17
Posted 19 March 2009 - 02:32 PM
Hyper said:
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
Posted 19 March 2009 - 04:00 PM
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
Posted 19 March 2009 - 08:49 PM
Hyper said:
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).
not trying to lay any blame on you.
it sounded to me you wanted me to guess what the codes does.
#20
Posted 19 March 2009 - 08:54 PM
Hyper said:
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).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












