C++ reference manual bool PDF

Title C++ reference manual bool
Author Anonymous User
Course Computer science
Institution Guru Kashi University
Pages 144
File Size 5.7 MB
File Type PDF
Total Downloads 37
Total Views 153

Summary

C++ reference book...


Description

cplusplus.com

C++ Language Tutorial

Written by: Juan Soulié Last revision: June, 2007

Available online at:

 The online version is constantly revised and may contain corrections and changes

T he C++ L angua ge Tutoriaal

This document and its content is copyright of cplusplus.com © cplusplus.com, 2008. All rights reserved. Any redistribution or reproduction of part or all of the content in any form is prohibited other than to print a personal copy of the entire document or download it to a local hard disk, without modifying its content in any way (including, but not limited to, this copyright notice). You may not, except with express written permission from cplusplus.com, distribute the content of this document. Nor may you transmit it or store it in any other website or other form of electronic retrieval system. 

 

T he C++ L angua ge Tutoriaal

Table of contents Table of contents ...............................................................................................................................3 Introduction ......................................................................................................................................5 Instructions for use ................................................................................................................................... 5 Basics of C++ ......................................................................................................................................7 Structure of a program ............................................................................................................................. 7 Variables. Data Types.............................................................................................................................. 11 Constants ................................................................................................................................................ 17 Operators ................................................................................................................................................ 21 Basic Input/Output.................................................................................................................................. 29 Control Structures ............................................................................................................................ 34 Control Structures................................................................................................................................... 34 Functions (I) ............................................................................................................................................ 41 Functions (II) ........................................................................................................................................... 47 Compound data types ...................................................................................................................... 54 Arrays ...................................................................................................................................................... 54 Character Sequences .............................................................................................................................. 60 Pointers ................................................................................................................................................... 63 Dynamic Memory.................................................................................................................................... 74 Data structures........................................................................................................................................ 77 Other Data Types .................................................................................................................................... 82 Object Oriented Programming.......................................................................................................... 86 Classes (I)................................................................................................................................................. 86 Classes (II) ............................................................................................................................................... 95 Friendship and inheritance ................................................................................................................... 100 Polymorphism ....................................................................................................................................... 107 Advanced concepts ........................................................................................................................ 113 Templates.............................................................................................................................................. 113 Namespaces .......................................................................................................................................... 120 Exceptions ............................................................................................................................................. 123 Type Casting .......................................................................................................................................... 127



 

T he C++ L angua ge Tutoriaal

Preprocessor directives......................................................................................................................... 133 C++ Standard Library ...................................................................................................................... 138 Input/Output with files ......................................................................................................................... 138



 

T he C++ L angua ge Tutoriaal

Introduction

      ! " #  "!! $$!"    %&   '()"&

 * +$  !    ,$ #" $    $ '$  $-. $ !./

 '()"&"  ( 0112!33(!$ 401536  '()"&!    &&'()"& "!  

 $$ 



 

T he C++ L angua ge Tutoriaal

'. 

*

 

T he C++ L angua ge Tutoriaal

Basics of C++

 7    ! 8 Hello World! // my first program in C++ #include using namespace std; int main () { cout   4{}6;  $

2

 

T he C++ L angua ge Tutoriaal

 '$ "!   cout! #4Hello World#6 46 coutiostreamstd!.   (4;6  $ 4$6     4 $ 06'3 $$  +$ 4  //6. 4  #6 4! 6!4cout6!    4{}6    ! ! =$! int main () { cout 



1

< > =



03

== !=

#

00

&

'(-

0

^

I>

0

|

>

0

&&

'(-

0

||

>

0*

?:



02

= *= /= %= += .= >>= A/ ;&!!   ! "..n;   4n6 &4n>06   8 !n 0!&     

 "8 do statement while (condition); "$!$condition& $ !$statementcondition =$!$ 0 // number echoer #include using namespace std; int main () { unsigned long n; do { cout > n; cout title ;#8 (*pmovie).title B$pmovie.>title(*pmovie).title   title pmovie" 8 *pmovie.title #8 *(pmovie.title) '  title % pmovie4 6?    8

53

 

T he C++ L anguagge T utoriaal

86 E$ 87$   ,   % &N  ,   %  4E6  E  @    % E4 6

 )   struct movies_t { string title; int year; }; struct friends_t { string name; string email; movies_t favorite_movie; } charlie, maria; friends_t * pfriends = &charlie; '$8 charlie.name maria.favorite_movie.title charlie.favorite_movie.year pfriends.>favorite_movie.year 4! !$ 6

50

 

T he C++ L anguagge T utoriaal

) &(  $; typedef!8 typedef existing_type new_type_name ; existing_typenew_type_name =$8 typedef typedef typedef typedef

char C; unsigned int WORD; char * pChar; char field [50];

"8C!WORD!pCharfieldchar!unsigned int!char* char[50]!8 C mychar, anotherchar, *ptc1; WORD myword; pChar ptc2; field name; typedef"$ myword  WORDunsigned int!  typedef #"  ! 

B K ! "  8 union union_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; . . } object_names; 'union"? =$8

5

 

T he C++ L anguagge T utoriaal

union mytypes_t { char c; int i; float f; } mytypes; 8 mytypes.c mytypes.i mytypes.f )! ;   =$8 union mix_t { long l; struct { short hi; short lo; } s; char c[4]; } mix;  8mix.l!mix.smix.c  !long&! shortchar!"$! =47 6! 8

 $     

* ""!      =$!  8

5

 

T he C++ L anguagge T utoriaal

  struct { struct { char title[50]; char title[50]; char author[50]; char author[50]; union { union { float dollars; float dollars; int yens; int yens; }; } price; } book; } book;   4price6 dollars yens %= %! 8 book.price.dollars book.price.yens  %! 8 book.dollars book.yens " ! dollarsyens  + price!  

8&( A "8 enum enumeration_name { value1, value2, value3, . . } object_names; =$! color8...


Similar Free PDFs