Welcome, Guest
You last visited:


You are not connected. Please login or register

C++ Quick Refrences

View previous topic View next topic Go down  Message [Page 1 of 1]

1 C++ Quick Refrences on Sat Nov 06, 2010 7:11 am

Blacksun

avatar
GFX Team
GFX Team
Introduction thanks to bioshockfreak
Today I will show you guys the basics of symbols use in C++, such as syntax and information for commonly used tasks, syntax, and more! Also this guide is good for beginners to experts, just to refresh there mind for experts. And for the beginners, you can use this references to make your own projects. And if you have questions about this please do so. I'll make myself specific as best as I can and post all of the commands needed. Here are the following I will be listing:

* Headers
* Namespace
* Data Types
* Comments
* Arithmetic Operators
* Relational Operators
* Logical Operators
* Pointers
* If/Else Statements
* For Loops
* While Loops
* Do While Loops
* Switch Statements
* Arrays
* I/O Operators
* File I/O
* File Mode Constants
* Function Prototypes
* Class Prototypes
* Structure Prototypes
* Accessing Data Structures

So lets get started...

C++ Command List

Include Headers:
#include

Common Headers:
iostream, fstream, math, cctype, string

Namespace:
using namespace std;

Data Types:
int, char, float, double, void, bool

Comments:
//Comment text
/* Multi-Line comment text*/

Arithmetic Operators:
+(Addition), -(Subtraction), *(Multiplication), /(Division), %(Modulus)

Relational Operators:
<(Less than), <=(Less than or Equal to), >(Greater than), >=(Greater than or Equal to), ==(Equal to), !=(Not equal to)

Logical Operators:
||(Logical OR), &&(Logical AND), !(Logical Not)

Pointers:
int *ptr //Define Pointer
ptr = &var //ptr set to address of var
var2 = *ptr //Set var2, to value of var1

If Else:
Code:
if()
{ ; }
else
{ ; }


For Loop:
for(;
{ ; }

While Loop:
while ()
{ ; }

Do-While Loop:
do{ ; }
while ();

Switch Statement:
Code:
switch()
{
case
;
break;
case ;
;
break;

case;
break;
[default:
;
break;]
}



Arrays:
//New 5 element array
int my Array[5];
//Array index starts at 0
//Access 3rd element
myArray[2]=var;

I/O Operators:
>> //Input Operator
<< //Output Operator
cin >> var1, var2, var3;
cout << "TEXT HERE" << var1 << endl;
cin.get(char*buffer, streamsize num, char delim);

File I/O:
Code:
fstream file;
file.open ("filename", //Reads and writes like cin and cout
file >> var;
file << "TEXT HERE"<< var << endl;
//Read Entire Line
getline (file,line);
//Reading Writing Binary Data
file.read(memory_block, size);
file.write(memory_block, size);
file.close();


File Mode Constants:
ios::in //Open file for reading
ios:ut //Opens file for writing
ios::ate //Seeks the EOF.I/O operations can occur anywhere
ios::app //Causes output to be appended at EOF
ios::trunc //Destroys the previous contents
ios::nocreate //Causes open() to fail if file doesn't already exist
ios::noreplace //Causes open() to fail if file already exist

Function Prototype:
(parameter list)
{ body of the function }

Class Prototype:
Code:
class
{
public:
//method_prototypes
protected:
//method_prototypes
private:
//method_prototypes
//data_attributes
};


Structure Prototype:
struct {
member_type1 member_name1;
member_type2 member_name2;
} ;

Accessing Data Structures:
//Access member variable from Struct/Class
myStruct.membervar1 = var;
//Call class method
myClass.method(args);
//Pointer to Struct/Class
myStructType *ptr;
ptr = &myStruct;
ptr->membervar1 = var;


_________________
[You must be registered and logged in to see this image.]
View user profile

2 Re: C++ Quick Refrences on Tue Nov 09, 2010 9:35 am

sunsucker

avatar
Top Member
Top Member
cool post

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum