View Full Version : learning about C++
bazso
03-16-2009, 11:23 AM
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.
Mattias Gustavsson
03-16-2009, 11:49 AM
Use visual studio. The express edition is totally free and great.
You won't find a better IDE for C++ than visual studio.
Hyper
03-16-2009, 12:43 PM
Dev-C++ (http://www.bloodshed.net/devcpp.html) 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++).
Mattias Gustavsson
03-16-2009, 12:55 PM
But why would you want to use something like Dev-C++ when there's Visual Studio? I don't get it...
bazso
03-16-2009, 12: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.
bazso
03-16-2009, 12:58 PM
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.
bazso
03-16-2009, 01:05 PM
Dev-C++ (http://www.bloodshed.net/devcpp.html) 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.
Hyper
03-16-2009, 01: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).
bazso
03-16-2009, 01:42 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).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?
bazso
03-16-2009, 01:45 PM
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.
rouncer
03-16-2009, 09:53 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.
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...
bazso
03-17-2009, 07:06 AM
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.
bazso
03-17-2009, 08:19 AM
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.
Hyper
03-17-2009, 02:16 PM
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;
}
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 (http://www.google.com/) and MSDN (http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx) are for. MSDN is literally a "library" of functions and full of explainations.
bazso
03-18-2009, 07:54 PM
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 (http://www.google.com/) and MSDN (http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx) are for. MSDN is literally a "library" of functions and full of explainations.coolness tya again
Hyper
03-18-2009, 10:12 PM
Welcome. Any opinions on how that looks? ;)
bazso
03-19-2009, 07:32 AM
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.
Hyper
03-19-2009, 09:00 AM
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 (http://www.bloodshed.net/dev/devcpp.html) (Dev-C++ is the IDE, the compiler is a GCC (works on Windows/Linux)) works great).
bazso
03-19-2009, 01:49 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 (http://www.bloodshed.net/dev/devcpp.html) (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.
bazso
03-19-2009, 01:54 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 (http://www.bloodshed.net/dev/devcpp.html) (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!!!
Hyper
03-20-2009, 08:23 AM
You compiled the program (it's called code, not a script)?
SamuraiCrow
03-20-2009, 07:34 PM
Personally, I'd use Code::Blocks (http://www.codeblocks.org) instead of DevC++. It's handy for jumping back and forth between Windows and Linux since there is a version for each. There's a Macintosh version on the way also. (I'd like to see you do THAT with Visual Studio. :lol: )
Yes, Code::Blocks is very nice. I used Dev-Cpp before, but gave up on it when there was no updates for about a year.
bazso
03-21-2009, 08:14 PM
ty for your help
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.