Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


My C++ Question Thread

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Wed Sep 17, 2008 7:56 pm    Post subject: My C++ Question Thread Reply with quote

Well, I started to learn C++ today.

Obviously i'm starting with consoles for many reasons, and than moving on to Win32 API.

I will post all my questions here, so I dont end up making like 50 threads...

1st Question: Why does my program open than close? - SOLVED

My source:
Code:
 //my first program in C++, Sep. 17, 2008

#include <iostream>
using namespace std;

int main()

{
   cout << "Hello World";
   return 0;
}


2nd Question: When I use 'int' instead of 'double' my answer is different. -SOLVED
Code:
// Defined Constants: Calculating Circumference. Sep 18, 2008.


#include <iostream>
using namespace std;

// Define our constants:
#define PI 3.14159
#define NEWLINE '\n'

int main()
{
   double r=5.0; //radius
   double circle;

   circle = 2*PI *r;
   cout << circle;
   cout << NEWLINE;

   cin.sync();
   cin.ignore();
   return 0;
}

_________________


Last edited by AndrewMan on Thu Sep 18, 2008 6:24 pm; edited 6 times in total
Back to top
View user's profile Send private message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Wed Sep 17, 2008 8:01 pm    Post subject: Reply with quote

That's what a console application does.

Start -> Run...
Type in cmd
Navigate to your directory using "cd <dir>", for example:
cd "C:\Documents\C++ Projects\Hello World\bin"
Type in the name of the executable and press enter. The output should appear Smile

If you want to get round this, cin a single char at the end of your main method. The application will halt at the end, waiting for user input. When the user presses any key, the application will close.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Sep 17, 2008 8:04 pm    Post subject: Reply with quote

It's because you are instantly returning (in this case closing your program) right after outputting your text. To pause your program put these two lines of code before return 0.

Code:

cin.sync();
cin.ignore();

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Wed Sep 17, 2008 9:07 pm    Post subject: Reply with quote

Thanks guys, more question to come tomorrow as I start working with user input.
_________________
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Wed Sep 17, 2008 9:50 pm    Post subject: Reply with quote

Use getchar(); or system("pause");
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Wed Sep 17, 2008 9:59 pm    Post subject: Reply with quote

_void_ wrote:
Use getchar(); or system("pause");
No, bad.
_________________
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Sep 17, 2008 10:24 pm    Post subject: Reply with quote

_void_ wrote:
Use getchar(); or system("pause");


rofl, probably some of the worst advice i've seen in a long time on CEF.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Sep 18, 2008 2:32 am    Post subject: Reply with quote

Overload wrote:
_void_ wrote:
Use getchar(); or system("pause");


rofl, probably some of the worst advice i've seen in a long time on CEF.


It's void, what'd you expect? ^_^.

Heres some stuff so you dont even need to ask for it:

Code:
void _inline pause(void) {
   std::cin.sync(); std::cin.ignore();
}


Code:
void _inline mincls(void) {
   COORD start = {0, 0};
   std::cout.fill(' ');
   SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), start );
}


Code:
void fullcls(void) {
   HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
   COORD coord = {0, 0}; DWORD count;

   CONSOLE_SCREEN_BUFFER_INFO csbi;
   GetConsoleScreenBufferInfo(hStdOut, &csbi);

   FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
   SetConsoleCursorPosition(hStdOut, coord);
}


Function names pretty much tell you everything.
Back to top
View user's profile Send private message MSN Messenger
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Thu Sep 18, 2008 6:04 pm    Post subject: Reply with quote

Thanks sooo much for the help guys, you all so damn helpful.

Edit: New question added.

_________________
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Thu Sep 18, 2008 6:09 pm    Post subject: Reply with quote

int does not support decimals. you can use it, but it wouldn't be as accurate as float or double.
_________________
Back to top
View user's profile Send private message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Thu Sep 18, 2008 6:15 pm    Post subject: Reply with quote

HalfPrime wrote:
int does not support decimals. you can use it, but it wouldn't be as accurate as float or double.


Ahh I see, no wonder why my answer had no decimals.

Thanks HalfPrime Very Happy

_________________
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Thu Sep 18, 2008 6:52 pm    Post subject: Reply with quote

It get's the job done and that's all I want.
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Thu Sep 18, 2008 10:08 pm    Post subject: Reply with quote

_void_ wrote:
It get's the job done and that's all I want.

Gets it done very horribly.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
Travis13
Expert Cheater
Reputation: 0

Joined: 17 Feb 2007
Posts: 199

PostPosted: Fri Sep 26, 2008 11:43 am    Post subject: Reply with quote

add this question and answer PLEASE Smile.......how do u set only specific parts of the wording coloured like this?

cout << "Hello World" << endl;

but i only want "World" in red and keep everything else the same

i know its been ansered many times before but i cant find it and its a good addition to this thread

Thanks,
Travis13

_________________
Learning C++, trying, failing, never gonna give up tho Razz
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Sep 26, 2008 2:25 pm    Post subject: Reply with quote

Take a look at:

GetStdHandle
SetConsoleTextAttribute
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites