Monthly Archives: March 2013

C++ || Snippet – How To Display The Current Working Directory

The following is sample code which demonstrates how to display the current working directory of the program when its properties were initialized.

If you are a system admin, this has a similar effect to the “echo %CD%” Windows Shell command or the “pwd” Unix/Linux terminal command, which essentially displays the current working directory the program is located at.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output
Note: This was compiled using a Windows computer

This file is located in directory:

C:UsersAdminDesktop

Please press ENTER to continue...

C++ || Snippet – How To Convert A Decimal Number Into Binary

This page will demonstrate how to convert a decimal number (i.e a whole number) into its binary equivalent. So for example, if the decimal number of 26 was entered into the program, it would display the converted binary value of 11010.

REQUIRED KNOWLEDGE FOR THIS SNIPPET

How To Count In Binary
The "Long" Datatype - What Is It?
While Loops
Online Binary to Decimal Converter - Verify For Correct Results
How To Reverse A String

If you are looking for sample code which converts binary to decimal, check back here soon!


The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output
Note: The code was compiled 3 separate times to display different output

====== RUN 1 ======

Please enter an integer value: 1987

The integer value of 1987 = 11111000011 in binary

====== RUN 2 ======

Please enter an integer value: -26

The integer value of -26 = -11010 in binary

====== RUN 3 ======

Please enter an integer value: 12345678910

The integer value of 12345678910 = 1011011111110111000001110000111110 in binary