-->Programy C++ składają się z obiektów, funkcji, zmiennych i innych elementów[Author ID1: at Fri Sep 1 02:37:00 2006 ] składowych[Author ID2: at Tue Nov 13 10:15:00 2001 ]-->. Większość tej książki [Author ID1: at Fri Sep 1 02:37:00 2006 ]jest poświęcona dogłębnemu [Author ID2: at Tue Nov 13 10:15:00 2001 ]stanowi obszerny [Author ID2: at Tue Nov 13 10:15:00 2001 ]-->opis[Author ID1: at Fri Sep 1 02:37:00 2006 ]owi[Author ID2: at Tue Nov 13 10:15:00 2001 ]--> tych elementów, [Author ID1: at Fri Sep 1 02:37:00 2006 ]ale by[Author ID2: at Tue Nov 13 10:16:00 2001 ]jednakże w celu[Author ID2: at Tue Nov 13 10:16:00 2001 ]--> zrozumie[Author ID1: at Fri Sep 1 02:37:00 2006 ]ć[Author ID2: at Tue Nov 13 10:16:00 2001 ]nia[Author ID2: at Tue Nov 13 10:16:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]zasad ich współdziałania, [Author ID2: at Tue Nov 13 10:16:00 2001 ]jak one do siebie pasują, [Author ID2: at Tue Nov 13 10:16:00 2001 ]-->musisz najpierw poznać [Author ID1: at Fri Sep 1 02:37:00 2006 ]pełny [Author ID2: at Tue Nov 13 10:16:00 2001 ]cały [Author ID2: at Tue Nov 13 10:16:00 2001 ]-->działający program.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W tym rozdziale:[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Nawet prosty program [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->HELLO.cpp[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> z rozdziału pierwszego, „Zaczynamy”, miał wiele interesujących elementów. W tym podrozdziale omówimy go bardziej szczegółowo. Listing 2.1 [Author ID1: at Fri Sep 1 02:37:00 2006 ]zawiera [Author ID2: at Tue Nov 13 10:17:00 2001 ]-->przypom[Author ID1: at Fri Sep 1 02:37:00 2006 ]n[Author ID2: at Tue Nov 13 10:17:00 2001 ]-->i[Author ID1: at Fri Sep 1 02:37:00 2006 ]enie[Author ID2: at Tue Nov 13 10:17:00 2001 ]na[Author ID2: at Tue Nov 13 10:17:00 2001 ]--> treś[Author ID1: at Fri Sep 1 02:37:00 2006 ]ci[Author ID2: at Tue Nov 13 10:17:00 2001 ]ć[Author ID2: at Tue Nov 13 10:17:00 2001 ]--> programu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->HELLO.cpp[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> z poprzedniego rozdziału.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.1. [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->HELLO.cpp[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> demonstruje elementy programu C++[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:17:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: std::cout << "Witaj Swiecie!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik działania[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:17:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Witaj Swiecie![Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->[Author ID0: at Thu Nov 30 00:00:00 1899 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza:[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 0[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:18:00 2001 ]--> do bieżącego pliku jest dołączany plik [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->iostream[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Oto [Author ID1: at Fri Sep 1 02:37:00 2006 ]jak to[Author ID2: at Tue Nov 13 10:18:00 2001 ]sposób jego[Author ID2: at Tue Nov 13 10:18:00 2001 ]--> działa[Author ID1: at Fri Sep 1 02:37:00 2006 ]nia[Author ID2: at Tue Nov 13 10:19:00 2001 ]-->: pierwszy znak jest symbolem [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->#[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, który stanowi sygnał dla preprocesora. Za każdym razem gdy uruchamiasz kompilację, uruchamiany jest preprocesor. Preprocesor odczytuje kod źródłowy, wyszukując linii zaczynających się od znaku [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->#[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> (hasz) i operuje na nich jeszcze przed uruchomieniem właściwego kompilatora. Preprocesor zostanie szczegółowo [Author ID1: at Fri Sep 1 02:37:00 2006 ]omówiony [Author ID2: at Tue Nov 13 10:19:00 2001 ]opisany [Author ID2: at Tue Nov 13 10:19:00 2001 ]-->w rozdziale 21., „Co dalej.”[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Polecenie [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->#include[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest instrukcją preprocesora[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:19:00 2001 ]--> mówiącą mu: „Po mnie następuje nazwa pliku. Znajdź ten plik i wstaw go w to miejsce.” Nawiasy kątowe dookoła nazwy pliku informują preprocesor[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:19:00 2001 ]--> by szukał pliku w standardowych miejscach dla tego typu plików. Jeśli twój kompilator jest odpowiednio skonfigurowany, nawiasy kątowe powodują[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:19:00 2001 ]--> że preprocesor szuka pliku [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->iostream[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> w kartotece zawierającej wszystkie pliki nagłówkowe dostarczane wraz z kompilatorem. Plik [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->iostream[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> (Input Output Stream — strumień wejścia-wyjścia) jest używany przez obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, asystujący przy wypisywaniu tekstu na ekranie. Efektem [Author ID1: at Fri Sep 1 02:37:00 2006 ]działania [Author ID2: at Tue Nov 13 10:19:00 2001 ]-->linii 0[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:19:00 2001 ]--> jest wstawienie zawartości pliku [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->iostream[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]w [Author ID2: at Tue Nov 13 10:20:00 2001 ]do [Author ID2: at Tue Nov 13 10:20:00 2001 ]-->kod[Author ID1: at Fri Sep 1 02:37:00 2006 ]u[Author ID2: at Tue Nov 13 10:20:00 2001 ]--> programu, tak jakby został on wpisany przez ciebie. Preprocesor działa przed każdym rozpoczęciem kompilacji, poprzedzając jej właściwą fazę. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Preprocesor tłumaczy[Author ID2: at Tue Nov 13 10:20:00 2001 ]Ponadto zamienia[Author ID2: at Tue Nov 13 10:20:00 2001 ]--> wszystkie linie rozpoczynające się od znaku hasz ([Author ID1: at Fri Sep 1 02:37:00 2006 ]-->#[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->) na specjalne polecenia, przygotowując ostateczny kod źródłowy dla kompilatora.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Linia 2[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:20:00 2001 ]--> rozpoczyna rzeczywisty program od funkcji o nazwie [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Funkcję tę posiada każdy program C++. Funkcja jest blokiem kodu wykonującym jedną lub więcej operacji. Zwykle funkcje są wywoływane przez inne funkcje, lecz funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ] jest [Author ID2: at Tue Nov 13 10:20:00 2001 ]-->pod tym względem [Author ID1: at Fri Sep 1 02:37:00 2006 ]specjalna[Author ID2: at Tue Nov 13 10:20:00 2001 ]odbiega od standardu[Author ID2: at Tue Nov 13 10:20:00 2001 ]-->. Gdy program rozpoczyna działanie, [Author ID1: at Fri Sep 1 02:37:00 2006 ]funkcja [Author ID2: at Tue Nov 13 10:21:00 2001 ]main()[Author ID2: at Tue Nov 13 10:21:00 2001 ] [Author ID2: at Tue Nov 13 10:21:00 2001 ]-->jest [Author ID1: at Fri Sep 1 02:37:00 2006 ]ona [Author ID2: at Tue Nov 13 10:21:00 2001 ]-->wywoływana automatycznie.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main ()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, podobnie jak inne funkcje, musi określić rodzaj zwracanej przez siebie wartości. Typem [Author ID1: at Fri Sep 1 02:37:00 2006 ]zwracanej przez nią w programie [Author ID2: at Tue Nov 13 10:21:00 2001 ]HELLO.cpp[Author ID2: at Tue Nov 13 10:21:00 2001 ] [Author ID2: at Tue Nov 13 10:21:00 2001 ]-->wartości [Author ID1: at Fri Sep 1 02:37:00 2006 ]zwracanej przez funkcję [Author ID2: at Tue Nov 13 10:21:00 2001 ]main()[Author ID2: at Tue Nov 13 10:21:00 2001 ] w programie [Author ID2: at Tue Nov 13 10:21:00 2001 ]HELLO.cpp[Author ID2: at Tue Nov 13 10:21:00 2001 ] [Author ID2: at Tue Nov 13 10:21:00 2001 ]-->jest typ [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->int[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, [Author ID1: at Fri Sep 1 02:37:00 2006 ]c[Author ID2: at Tue Nov 13 10:21:00 2001 ]t[Author ID2: at Tue Nov 13 10:21:00 2001 ]-->o oznacza że po zakończeniu działania [Author ID1: at Fri Sep 1 02:37:00 2006 ]ta [Author ID2: at Tue Nov 13 10:22:00 2001 ]-->funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]ta [Author ID2: at Tue Nov 13 10:22:00 2001 ]-->zwraca systemowi operacyjnemu wartość całkowitą (ang. [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->integer[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->). W tym przypadku zwracaną wartością jest [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, tak jak to widzimy w linii 5. Zwrócenie wartości systemowi operacyjnemu jest stosunkowo mało ważną i rzadko wykorzystywaną możliwością, ale standard C++ wymaga[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:22:00 2001 ]--> by funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]była [Author ID2: at Tue Nov 13 10:22:00 2001 ]została [Author ID2: at Tue Nov 13 10:22:00 2001 ]-->zadeklarowana tak jak pokazano.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA Niektóre kompilatory pozwalają na deklarację [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ] [Author ID2: at Tue Nov 13 10:22:00 2001 ], [Author ID2: at Tue Nov 13 10:22:00 2001 ]-->jeśli funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> ma zwracać typ [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->void[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Nie jest to zgodne ze standardem C++ i nie powinieneś się do tego przyzwyczajać. Niech funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> zwraca wartość typu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->int[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, zaś w ostatniej linii tej funkcji po prostu zwracaj wartość [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA Niektóre systemy operacyjne umożliwiają sprawdzanie (testowanie)[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:22:00 2001 ]--> jaka wartość została zwrócona przez program. Zgodnie z konwencją, zwrócenie wartości [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> oznacza, że program [Author ID1: at Fri Sep 1 02:37:00 2006 ]normalnie [Author ID2: at Tue Nov 13 10:22:00 2001 ]-->zakończył działanie[Author ID1: at Fri Sep 1 02:37:00 2006 ] normalnie[Author ID2: at Tue Nov 13 10:22:00 2001 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wszystkie funkcje rozpoczynają się od nawiasu otwierającego ([Author ID1: at Fri Sep 1 02:37:00 2006 ]-->{[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->) i kończą nawiasem zamykającym (}). Nawiasy dla funkcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> znajdują się w liniach 3[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:23:00 2001 ]--> i 6. Wszystko[Author ID1: at Fri Sep 1 02:37:00 2006 ], co znajduje się[Author ID2: at Tue Nov 13 10:23:00 2001 ]--> pomiędzy nawiasem otwierającym a zamykającym[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:23:00 2001 ]--> jest uważane za treść funkcji.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Prawdziwa [Author ID1: at Fri Sep 1 02:37:00 2006 ]zawartość [Author ID2: at Tue Nov 13 10:23:00 2001 ]treść [Author ID2: at Tue Nov 13 10:23:00 2001 ]-->programu znajduje się w linii 4. Obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest używany do wypisywania komunikatów na ekranie. Obiektami zajmiemy się [Author ID1: at Fri Sep 1 02:37:00 2006 ]ogólnie [Author ID2: at Tue Nov 13 10:24:00 2001 ]-->w rozdziale 6., „Programowanie zorientowane obiektowo”, zaś obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i powiązany z nim obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cin[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> omówimy szczegółowo w rozdziale 17., „Strumienie.” Te dwa obiekty, [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cin[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, są w C++ używane, odpowiednio[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:24:00 2001 ]:[Author ID2: at Tue Nov 13 10:24:00 2001 ]--> do obsługi wejścia (na przykład z klawiatury) oraz wyjścia (na przykład na ekran).[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest dostarczany przez [Author ID1: at Fri Sep 1 02:37:00 2006 ]bibliotekę [Author ID2: at Tue Nov 13 10:24:00 2001 ]-->standardową[Author ID1: at Fri Sep 1 02:37:00 2006 ] bibliotekę[Author ID2: at Tue Nov 13 10:24:00 2001 ]-->. Biblioteka jest kolekcją klas. Standardowa biblioteka jest standardową kolekcją dostarczaną [Author ID1: at Fri Sep 1 02:37:00 2006 ]wraz [Author ID2: at Tue Nov 13 10:24:00 2001 ]-->z każdym kompilatorem zgodnym z ANSI.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Używając specyfikatora przestrzeni nazw, [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->std[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, informujemy kompilator[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:24:00 2001 ]--> że obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest częścią biblioteki standardowej. Ponieważ możesz mieć kilka, pochodzących od różnych dostawców, obiektów o tych samych nazwach, C++ dzieli „świat” na „przestrzenie nazw[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:24:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]. [Author ID2: at Tue Nov 13 10:24:00 2001 ] [Author ID2: at Tue Nov 13 10:24:00 2001 ]-->Przestrzeń nazw jest sposobem na powiedzenie[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:25:00 2001 ]--> że: „gdy mówię [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, mam na myśli to, że [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest częścią standardowej przestrzeni nazw, a nie jakiejś innej przestrzeni nazw.” Mówimy to kompilatorowi poprzez umieszczenie przed nazwą [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> znaków [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->sdt[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i podwójnego dwukropka. Więcej na temat różnych przestrzeni nazw powiemy [Author ID1: at Fri Sep 1 02:37:00 2006 ]sobie [Author ID2: at Tue Nov 13 10:25:00 2001 ]-->w następnych rozdziałach.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Oto [Author ID1: at Fri Sep 1 02:37:00 2006 ]jak [Author ID2: at Tue Nov 13 10:25:00 2001 ]sposób [Author ID2: at Tue Nov 13 10:25:00 2001 ]-->uży[Author ID1: at Fri Sep 1 02:37:00 2006 ]wany[Author ID2: at Tue Nov 13 10:25:00 2001 ]cia[Author ID2: at Tue Nov 13 10:25:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]jest [Author ID2: at Tue Nov 13 10:25:00 2001 ]-->obiekt[Author ID1: at Fri Sep 1 02:37:00 2006 ]u[Author ID2: at Tue Nov 13 10:25:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->: wpisz słowo [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, a po nim operator przekierowania wyjścia ([Author ID1: at Fri Sep 1 02:37:00 2006 ]--><<[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->). To, co następuje po operatorze przekierowania wyjścia, zostanie wypisane na ekranie. Jeśli chcesz[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:25:00 2001 ]--> by został wypisany łańcuch znaków, pamiętaj o ujęciu go w cudzysłowy[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:25:00 2001 ] ([Author ID2: at Tue Nov 13 10:25:00 2001 ] [Author ID2: at Tue Nov 13 10:25:00 2001 ]-->tak jak widzimy w linii 4.[Author ID1: at Fri Sep 1 02:37:00 2006 ])[Author ID2: at Tue Nov 13 10:25:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Łańcuch tekstowy jest serią [Author ID1: at Fri Sep 1 02:37:00 2006 ]znaków [Author ID2: at Tue Nov 13 10:26:00 2001 ]-->drukowalnych[Author ID1: at Fri Sep 1 02:37:00 2006 ] znaków[Author ID2: at Tue Nov 13 10:25:00 2001 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Dwa ostatnie znaki, [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->\n[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, informują obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ] [Author ID2: at Tue Nov 13 10:26:00 2001 ], [Author ID2: at Tue Nov 13 10:26:00 2001 ]-->by po słowach [Author ID1: at Fri Sep 1 02:37:00 2006 ][Author ID2: at Tue Nov 13 10:26:00 2001 ]-->Witaj Świecie![Author ID1: at Fri Sep 1 02:37:00 2006 ][Author ID2: at Tue Nov 13 10:26:00 2001 ]--> umieścił nową linię. Ten specjalny kod zostanie [Author ID1: at Fri Sep 1 02:37:00 2006 ]wyjaśniony [Author ID2: at Tue Nov 13 10:26:00 2001 ]opisany [Author ID2: at Tue Nov 13 10:26:00 2001 ]-->szczegółowo podczas omawiania obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> w rozdziale 18., „Przestrzenie nazw.”[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> kończy się w linii 6[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:26:00 2001 ]--> nawiasem zamykającym.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W rozdziale 17. zobaczysz[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:26:00 2001 ]--> w jaki sposób używa się obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> do wypisywania danych na ekranie. Na razie możesz z niego korzystać[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:27:00 2001 ]--> nie wiedząc[Author ID1: at Fri Sep 1 02:37:00 2006 ] właściwie[Author ID2: at Tue Nov 13 10:27:00 2001 ],[Author ID2: at Tue Nov 13 10:27:00 2001 ]--> jak działa. Aby wypisać wartość na ekranie, napisz słowo [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, po nim operator wstawiania ([Author ID1: at Fri Sep 1 02:37:00 2006 ]--><<[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->), uzyskiwany w wyniku dwukrotnego wpisania znaku mniejszości ([Author ID1: at Fri Sep 1 02:37:00 2006 ]--><[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->). Choć w rzeczywistości są to dwa znaki, C++ traktuje je jako pojedynczy symbol.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Po znaku wstawiania wpisz [Author ID1: at Fri Sep 1 02:37:00 2006 ]dane [Author ID2: at Tue Nov 13 10:27:00 2001 ]-->przeznaczone do wypisania[Author ID1: at Fri Sep 1 02:37:00 2006 ] dane[Author ID2: at Tue Nov 13 10:27:00 2001 ]-->. Listing 2.2 ilustruje sposób użycia tego obiektu. Wpisz w tym przykładzie dokładnie to[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:28:00 2001 ]--> co[Author ID1: at Fri Sep 1 02:37:00 2006 ] pokazano[Author ID2: at Tue Nov 13 10:28:00 2001 ]--> na listingu, z [Author ID1: at Fri Sep 1 02:37:00 2006 ]wyjątkiem tego[Author ID2: at Tue Nov 13 10:28:00 2001 ]tym[Author ID2: at Tue Nov 13 10:28:00 2001 ]-->, że zamiast nazwiska Jesse Liberty wpisz swoje własne (chyba[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:28:00 2001 ]--> że rzeczywiście nazywasz się [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->Jesse Liberty[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->).[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.2. Użycie [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:28:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: // Listing 2.2 użycie std::cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: std::cout << "Hej tam.\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: std::cout << "To jest 5: " << 5 << "\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: std::cout << "Manipulator std::endl ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: std::cout << "wypisuje nowa linie na ekranie.";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: std::cout << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: std::cout << "To jest bardzo duza liczba:\t" << 70000;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: std::cout << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: std::cout << "To jest suma 8 i 5:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: std::cout << 8+5 << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: std::cout << "To jest ulamek:\t\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: std::cout << (float) 5/8 << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: std::cout << "I bardzo, bardzo duza liczba:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: std::cout << (double) 7000 * 7000 << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->17: std::cout << "Nie zapomnij zamienic Jesse Liberty ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->18: std::cout << "na swoje nazwisko...\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->19: std::cout << "Jesse Liberty jest programista C++!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->20: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->21: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik działania[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:28:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Hej tam.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest 5: 5[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Manipulator std::endl wypisuje nowa linie na ekranie.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest bardzo duza liczba: 70000[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest suma 8 i 5: 13[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest ulamek: 0.625[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->I bardzo, bardzo duza liczba: 4.9e+007[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Nie zapomnij zamienic Jesse Liberty na swoje nazwisko...[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Jesse Liberty jest programista C++![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA Niektóre kompilatory zawierają błąd[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:29:00 2001 ];[Author ID2: at Tue Nov 13 10:29:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]wymagający by [Author ID2: at Tue Nov 13 10:29:00 2001 ]-->przed przekazaniem sumy do obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]należy [Author ID2: at Tue Nov 13 10:29:00 2001 ]-->umieścić ją w nawiasach. Tak więc linia 12[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:29:00 2001 ]--> powinna być zmieniona na:[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->12 std::cout << (8+5) << std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza:[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 1[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:29:00 2001 ]-->, instrukcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->#include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> powoduje włączenie [Author ID1: at Fri Sep 1 02:37:00 2006 ]zawartości pliku [Author ID2: at Tue Nov 13 10:29:00 2001 ]iostream[Author ID2: at Tue Nov 13 10:29:00 2001 ] [Author ID2: at Tue Nov 13 10:29:00 2001 ]-->do kodu źródłowego[Author ID1: at Fri Sep 1 02:37:00 2006 ] zawartości pliku [Author ID2: at Tue Nov 13 10:29:00 2001 ]iostream[Author ID2: at Tue Nov 13 10:29:00 2001 ]-->. Jest ona wymagana[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:29:00 2001 ]--> jeśli używasz obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i powiązanych z nim funkcji.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 4[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:30:00 2001 ]--> znajduje się najprostsze zastosowanie obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, do wypisania ciągu znaków. Symbol [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->\n[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest specjalnym znakiem formatującym. Informuje on [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> by wypisał na ekranie znak nowej linii (tzn. aby dalsze wypisywanie rozpoczął od następnej linii ekranu).[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 5[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:31:00 2001 ]--> przekazujemy do [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> trzy wartości, oddzielone operatorem wstawiania. Pierwszą z tych wartości jest łańcuch [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->"To jest 5: "[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Zwróć uwagę na odstęp po dwukropku. Ten odstęp (spacja) jest częścią łańcucha. Następnie do operatora wstawiania jest przekazywana wartość [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> oraz znak nowej linii (zawsze w cudzysłowach lub apostrofach)[Author ID1: at Fri Sep 1 02:37:00 2006 ]. To[Author ID2: at Tue Nov 13 10:31:00 2001 ], co[Author ID2: at Tue Nov 13 10:31:00 2001 ]--> powoduje wypisanie na ekranie linii[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest 5: 5[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Ponieważ po pierwszym łańcuchu nie występuje znak nowej linii, następna wartość jest wypisywana tuż za nim. Nazywa się to konkatenacją (łączeniem) dwóch wartości.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 6[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:31:00 2001 ]--> wypisywany jest [Author ID1: at Fri Sep 1 02:37:00 2006 ]informacyjny [Author ID2: at Tue Nov 13 10:31:00 2001 ]-->komunikat[Author ID1: at Fri Sep 1 02:37:00 2006 ] informacyjny[Author ID2: at Tue Nov 13 10:31:00 2001 ]-->, po czym (w linii 8[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:31:00 2001 ]-->) [Author ID1: at Fri Sep 1 02:37:00 2006 ]następuje [Author ID2: at Tue Nov 13 10:32:00 2001 ]-->uży[Author ID1: at Fri Sep 1 02:37:00 2006 ]cie[Author ID2: at Tue Nov 13 10:32:00 2001 ]ty[Author ID2: at Tue Nov 13 10:32:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]zostaje [Author ID2: at Tue Nov 13 10:32:00 2001 ]-->manipulator[Author ID1: at Fri Sep 1 02:37:00 2006 ]a[Author ID2: at Tue Nov 13 10:32:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Przeznaczeniem [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest wypisanie nowej linii na ekranie. (Inne zastosowania dla [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> zostaną omówione w rozdziale 16.). Zwróć uwagę[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:32:00 2001 ]--> że [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> także pochodzi z biblioteki standardowej.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> pochodzi od słów „end line” (zakończ linię) i w rzeczywistości jest to „end-L”, a nie „end-jeden”.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 9[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:32:00 2001 ]--> został wprowadzony nowy znak formatujący, [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->\t[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Powoduje on wstawienie znaku tabulacji i jest używany [Author ID1: at Fri Sep 1 02:37:00 2006 ]w celu wyrównywania wydruków wyników [Author ID2: at Tue Nov 13 10:32:00 2001 ]-->w liniach od 9[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:32:00 2001 ]--> do 15[Author ID1: at Fri Sep 1 02:37:00 2006 ] w celu wyrównywania wydruków wyników[Author ID2: at Tue Nov 13 10:32:00 2001 ]-->. Linia 9[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> pokazuje[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> że [Author ID1: at Fri Sep 1 02:37:00 2006 ]wypisywane [Author ID2: at Tue Nov 13 10:33:00 2001 ]-->mogą być [Author ID1: at Fri Sep 1 02:37:00 2006 ]wypisywane [Author ID2: at Tue Nov 13 10:33:00 2001 ]-->nie tylko liczby całkowite, ale także długie liczby całkowite. Linia 12[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> demonstruje[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> że [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> potrafi wykonać proste dodawanie. Do obiektu jest przekazywana wartość [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8+5[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, lecz wypisywana jest suma 13.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 14[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> do [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest wstawiana wartość [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5/8[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Symbol [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->(float)[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> informuje [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ] [Author ID2: at Tue Nov 13 10:33:00 2001 ], [Author ID2: at Tue Nov 13 10:33:00 2001 ]-->że chcemy aby ta wartość została obliczona jako rozwinięcie dziesiętne, więc wypisywany jest ułamek. W linii 16[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:33:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> otrzymuje wartość [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7000 * 7000[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, zaś symbol [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->(double)[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> służy do poinformowania [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ] [Author ID2: at Tue Nov 13 10:34:00 2001 ], [Author ID2: at Tue Nov 13 10:34:00 2001 ]-->że jest to wartość zmiennoprzecinkowa. Wszystko to zostanie wyjaśnione w rozdziale 3., „Zmienne i stałe,” przy okazji omawiania typów danych.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->W linii 16[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:34:00 2001 ]--> podstawiłeś swoje nazwisko, zaś wynik potwierdza[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:34:00 2001 ]--> że naprawdę jesteś programistą C++. Musi być to prawda, skoro [Author ID1: at Fri Sep 1 02:37:00 2006 ]tak uważa [Author ID2: at Tue Nov 13 10:34:00 2001 ]-->komputer[Author ID1: at Fri Sep 1 02:37:00 2006 ] tak uważa[Author ID2: at Tue Nov 13 10:34:00 2001 ]-->![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Z pewnością zauważyłeś[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:34:00 2001 ]--> że przed każdym [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> występuje [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->std::[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, co po jakimś czasie może być irytujące. Choć korzystanie z odnośnika do przestrzeni nazw jest poprawn[Author ID1: at Fri Sep 1 02:37:00 2006 ]ą form[Author ID2: at Tue Nov 13 10:34:00 2001 ]e[Author ID2: at Tue Nov 13 10:34:00 2001 ]ą[Author ID2: at Tue Nov 13 10:34:00 2001 ]-->, jednak [Author ID1: at Fri Sep 1 02:37:00 2006 ]jest [Author ID2: at Tue Nov 13 10:34:00 2001 ]okazuje się [Author ID2: at Tue Nov 13 10:34:00 2001 ]-->dosyć żmudne przy wpisywaniu. Standard ANSI oferuje dwa rozwiązania te[Author ID1: at Fri Sep 1 02:37:00 2006 ]j[Author ID2: at Tue Nov 13 10:35:00 2001 ]go[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> niewielkie[Author ID1: at Fri Sep 1 02:37:00 2006 ]j[Author ID2: at Tue Nov 13 10:35:00 2001 ]go[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]niedogodności[Author ID2: at Tue Nov 13 10:35:00 2001 ]problemu[Author ID2: at Tue Nov 13 10:35:00 2001 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Pierwszym z nich jest poinformowanie kompilatora[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:35:00 2001 ] ([Author ID2: at Tue Nov 13 10:35:00 2001 ] [Author ID2: at Tue Nov 13 10:35:00 2001 ]-->na początku listingu kodu[Author ID1: at Fri Sep 1 02:37:00 2006 ])[Author ID2: at Tue Nov 13 10:35:00 2001 ],[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> że będziemy używać [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> z biblioteki standardowej, tak jak pokazano na listingu 2.3.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.3. Użycie słowa kluczowego [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:35:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: // Listing 2.3 - użycie słowa kluczowego "using"[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: using std::cout;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: using std::endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: cout << "Hej tam.\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: cout << "To jest 5: " << 5 << "\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: cout << "Manipulator endl ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: cout << "wypisuje nowa linie na ekranie.";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: cout << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: cout << "To jest bardzo duza liczba:\t" << 70000;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: cout << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: cout << "To jest suma 8 i 5:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: cout << 8+5 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: cout << "To jest ulamek:\t\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->17: cout << (float) 5/8 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->18: cout << "I bardzo, bardzo duza liczba:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->19: cout << (double) 7000 * 7000 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->20: cout << "Nie zapomnij zamienic Jesse Liberty ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->21: cout << "na swoje nazwisko...\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->22: cout << "Jesse Liberty jest programista C++!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->23: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->24: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik działania[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:35:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Hej tam.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest 5: 5[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Manipulator endl wypisuje nowa linie na ekranie.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest bardzo duza liczba: 70000[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest suma 8 i 5: 13[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->To jest ulamek: 0.625[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->I bardzo, bardzo duza liczba: 4.9e+007[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Nie zapomnij zamienic Jesse Liberty na swoje nazwisko...[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Jesse Liberty jest programista C++![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:35:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Zauważ[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> że wynik jest identyczny. Jedyną różnicą pomiędzy listingiem 2.3 [Author ID1: at Fri Sep 1 02:37:00 2006 ]i[Author ID2: at Tue Nov 13 10:35:00 2001 ]a[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> 2.2 jest to, że w liniach 4[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> i 5[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:35:00 2001 ]--> informujemy kompilator[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:36:00 2001 ]--> że będziemy używać dwóch obiektów ze standardowej biblioteki. Używamy do tego słowa kluczowego [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Gdy to zrobimy, nie musimy już kwalifikować obiektów [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Drugim sposobem uniknięcia [Author ID1: at Fri Sep 1 02:37:00 2006 ]niedogodności [Author ID2: at Tue Nov 13 10:36:00 2001 ]-->pisania [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->std::[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> przed [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest po prostu poinformowanie kompilatora[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:36:00 2001 ]--> że będziemy używać całej przestrzeni nazw standardowych[Author ID1: at Fri Sep 1 02:37:00 2006 ];[Author ID2: at Tue Nov 13 10:36:00 2001 ],[Author ID2: at Tue Nov 13 10:36:00 2001 ]--> tj[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:36:00 2001 ],[Author ID2: at Tue Nov 13 10:36:00 2001 ]--> że każdy obiekt, który nie zostanie oznaczony, z założenia będzie pochodził z przestrzeni nazw standardowych. W tym przypadku, zamiast pisać [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using std::cout;[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> napiszemy po prostu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using namespace std;[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, tak jak pokazano na listingu 2.4.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.4. Użycie słowa kluczowego [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->namespace[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:36:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: // Listing 2.3 - użycie przestrzeni nazw standardowych[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: using namespace std;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: cout << "Hej tam.\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: cout << "To jest 5: " << 5 << "\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: cout << "Manipulator endl ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: cout << "wypisuje nowa linie na ekranie.";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: cout << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: cout << "To jest bardzo duza liczba:\t" << 70000;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: cout << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: cout << "To jest suma 8 i 5:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: cout << 8+5 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: cout << "To jest ulamek:\t\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: cout << (float) 5/8 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->17: cout << "I bardzo, bardzo duza liczba:\t";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->18: cout << (double) 7000 * 7000 << endl;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->19: cout << "Nie zapomnij zamienic Jesse Liberty ",[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->20: cout << "na swoje nazwisko...\n",[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->21: cou << "Jesse Liberty jest programista C++!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->22: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->23: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:37:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Także tym razem wynik jest identyczny z [Author ID1: at Fri Sep 1 02:37:00 2006 ]wynikami uzyskiwanymi we [Author ID2: at Tue Nov 13 10:37:00 2001 ]-->wcześniejszy[Author ID1: at Fri Sep 1 02:37:00 2006 ]mi[Author ID2: at Tue Nov 13 10:37:00 2001 ]ch[Author ID2: at Tue Nov 13 10:37:00 2001 ]--> wersja[Author ID1: at Fri Sep 1 02:37:00 2006 ]mi[Author ID2: at Tue Nov 13 10:37:00 2001 ]ch[Author ID2: at Tue Nov 13 10:37:00 2001 ]--> programu. Zaletą zapisu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using namespace std;[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest to, że nie musimy określać obiektów, z których chcemy korzystać (na przykład [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> oraz [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->). Wadą jest [Author ID1: at Fri Sep 1 02:37:00 2006 ]to, że [Author ID2: at Tue Nov 13 10:37:00 2001 ]-->ryzyk[Author ID1: at Fri Sep 1 02:37:00 2006 ]ujemy[Author ID2: at Tue Nov 13 10:37:00 2001 ]o[Author ID2: at Tue Nov 13 10:37:00 2001 ]--> niezamierzone[Author ID1: at Fri Sep 1 02:37:00 2006 ]go[Author ID2: at Tue Nov 13 10:37:00 2001 ]--> użyci[Author ID1: at Fri Sep 1 02:37:00 2006 ]e[Author ID2: at Tue Nov 13 10:37:00 2001 ]a[Author ID2: at Tue Nov 13 10:37:00 2001 ]--> obiektów z niewłaściwej biblioteki.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Puryści preferują zapisywanie [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->std::[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> przed każdym wystąpieniem [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->endl[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Osoby bardziej leniwe wolą używać [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using namespace std;[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]i n[Author ID2: at Tue Nov 13 10:38:00 2001 ]N[Author ID2: at Tue Nov 13 10:38:00 2001 ]-->a tym zakończmy temat. W tej książce w większości przypadków będziemy pisać, z jakich obiektów korzystamy, ale od czasu do czasu, dla [Author ID1: at Fri Sep 1 02:37:00 2006 ]samej [Author ID2: at Tue Nov 13 10:38:00 2001 ]-->odmiany, [Author ID1: at Fri Sep 1 02:37:00 2006 ]sp[Author ID2: at Tue Nov 13 10:38:00 2001 ]wyp[Author ID2: at Tue Nov 13 10:38:00 2001 ]-->róbujemy także pozostał[Author ID1: at Fri Sep 1 02:37:00 2006 ]ych[Author ID2: at Tue Nov 13 10:38:00 2001 ]e[Author ID2: at Tue Nov 13 10:38:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]stylów[Author ID2: at Tue Nov 13 10:38:00 2001 ]style[Author ID2: at Tue Nov 13 10:38:00 2001 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Gdy piszesz program, [Author ID1: at Fri Sep 1 02:37:00 2006 ]to, co chcesz osiągnąć, [Author ID2: at Tue Nov 13 10:39:00 2001 ]-->zawsze jest jasne i oczywiste[Author ID1: at Fri Sep 1 02:37:00 2006 ] to, co chcesz osiągnąć[Author ID2: at Tue Nov 13 10:39:00 2001 ]-->. Jednak[Author ID1: at Fri Sep 1 02:37:00 2006 ] co zabawne,[Author ID2: at Tue Nov 13 10:39:00 2001 ]--> miesiąc [Author ID1: at Fri Sep 1 02:37:00 2006 ]gdy do niego wracasz [Author ID2: at Tue Nov 13 10:39:00 2001 ]-->później, [Author ID1: at Fri Sep 1 02:37:00 2006 ]gdy do niego wracasz, k[Author ID2: at Tue Nov 13 10:39:00 2001 ]k[Author ID2: at Tue Nov 13 10:39:00 2001 ]-->od może okazać się całkiem niezrozumiały. Nie jestem w stanie przewidzieć[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:40:00 2001 ]--> co może być niezrozumiałego w twoim programie, ale [Author ID1: at Fri Sep 1 02:37:00 2006 ]tak jest[Author ID2: at Tue Nov 13 10:40:00 2001 ]zdarza się to[Author ID2: at Tue Nov 13 10:40:00 2001 ]--> zawsze.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Aby sobie z tym poradzić, a także[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:40:00 2001 ]--> by pomóc innym w zrozumieniu twojego kodu, powinieneś używać komentarzy. Komentarze są tekstem całkowicie ignorowanym przez kompilator, [Author ID1: at Fri Sep 1 02:37:00 2006 ]lecz [Author ID2: at Tue Nov 13 10:40:00 2001 ]-->mogą [Author ID1: at Fri Sep 1 02:37:00 2006 ]natomiast [Author ID2: at Tue Nov 13 10:40:00 2001 ]-->informować czytającego o tym, co robisz w danym punkcie programu.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Komentarze w C++ występują w dwóch odmianach: jako komentarze podwójnego ukośnika ([Author ID1: at Fri Sep 1 02:37:00 2006 ]-->//[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->) oraz jako komentarze ukośnika i gwiazdki ([Author ID1: at Fri Sep 1 02:37:00 2006 ]-->/*[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->). Komentarz podwójnego ukośnika, nazywany komentarzem w stylu C++, informuje kompilator[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:40:00 2001 ]--> by zignorował wszystko[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:41:00 2001 ]--> co po nim następuje, aż do końca linii.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Komentarz ukośnika i gwiazdki informuje kompilator[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:41:00 2001 ]--> by zignorował wszystko to, co jest zawarte pomiędzy znakami [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->/*[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> oraz [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->*/[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Te znaki są nazywane komentarzami w stylu C. Każdemu znakowi [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->/*[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> musi odpowiadać zamykający komentarz znak [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->*/[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Jak można się domyślać, komentarze w stylu C są używane także w programach C[Author ID1: at Fri Sep 1 02:37:00 2006 ], lecz [Author ID2: at Tue Nov 13 10:41:00 2001 ]; jednakże [Author ID2: at Tue Nov 13 10:41:00 2001 ]-->komentarze C++ nie są częścią oficjalnej definicji języka C.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Większość programistów używa [Author ID1: at Fri Sep 1 02:37:00 2006 ]w większości przypadków[Author ID2: at Tue Nov 13 10:41:00 2001 ]przeważnie[Author ID2: at Tue Nov 13 10:41:00 2001 ]--> komentarzy w stylu C++, [Author ID1: at Fri Sep 1 02:37:00 2006 ]rezerwując [Author ID2: at Tue Nov 13 10:41:00 2001 ]-->komentarze w stylu C [Author ID1: at Fri Sep 1 02:37:00 2006 ]rezerwując dla[Author ID2: at Tue Nov 13 10:41:00 2001 ]do[Author ID2: at Tue Nov 13 10:41:00 2001 ]--> wyłączania z kompilacji większych bloków kodu. Komentarze w stylu C++ mogą występować w blokach kodu „[Author ID1: at Fri Sep 1 02:37:00 2006 ]wy[Author ID2: at Tue Nov 13 10:41:00 2001 ]s[Author ID2: at Tue Nov 13 10:41:00 2001 ]-->komentowanych” komentarzami w stylu C. Ignorowana jest zawartość całego „[Author ID1: at Fri Sep 1 02:37:00 2006 ]wy[Author ID2: at Tue Nov 13 10:42:00 2001 ]s[Author ID2: at Tue Nov 13 10:42:00 2001 ]-->komentowanego” bloku, [Author ID1: at Fri Sep 1 02:37:00 2006 ]w[Author ID2: at Tue Nov 13 10:42:00 2001 ]-->łącznie z komentarzami w stylu C++.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Niektórzy programiści zalecają stosowanie komentarzy przed każdą funkcją[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:42:00 2001 ] ([Author ID2: at Tue Nov 13 10:42:00 2001 ] [Author ID2: at Tue Nov 13 10:42:00 2001 ]-->w celu wyjaśnienia[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:42:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]jakie czynności [Author ID2: at Tue Nov 13 10:42:00 2001 ]co ta [Author ID2: at Tue Nov 13 10:42:00 2001 ]-->funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]robi [Author ID2: at Tue Nov 13 10:43:00 2001 ]wykonuje [Author ID2: at Tue Nov 13 10:43:00 2001 ]-->i jakie wartości zwraca[Author ID1: at Fri Sep 1 02:37:00 2006 ])[Author ID2: at Tue Nov 13 10:42:00 2001 ].[Author ID2: at Tue Nov 13 10:42:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Osobiście nie zgadzam się z tym, [Author ID1: at Fri Sep 1 02:37:00 2006 ]gdyż [Author ID2: at Tue Nov 13 10:43:00 2001 ]-->uważam[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:43:00 2001 ]--> że komentarze w nagłówkach funkcji zwykle są nieaktualne, bo prawie nikt nie pamięta o tym, by [Author ID1: at Fri Sep 1 02:37:00 2006 ]zaktualizować je [Author ID2: at Tue Nov 13 10:43:00 2001 ]-->po modyfikacji kodu[Author ID1: at Fri Sep 1 02:37:00 2006 ] je zaktualizować[Author ID2: at Tue Nov 13 10:43:00 2001 ]-->. Funkcje powinny [Author ID1: at Fri Sep 1 02:37:00 2006 ]mieć takie[Author ID2: at Tue Nov 13 10:43:00 2001 ]przyjmować takie[Author ID2: at Tue Nov 13 10:43:00 2001 ]--> nazwy, [Author ID1: at Fri Sep 1 02:37:00 2006 ]by [Author ID2: at Tue Nov 13 10:44:00 2001 ]-->na [Author ID1: at Fri Sep 1 02:37:00 2006 ]ich [Author ID2: at Tue Nov 13 10:44:00 2001 ]-->podstawie [Author ID1: at Fri Sep 1 02:37:00 2006 ]których [Author ID2: at Tue Nov 13 10:44:00 2001 ]-->można [Author ID1: at Fri Sep 1 02:37:00 2006 ]było [Author ID2: at Tue Nov 13 10:44:00 2001 ]-->jasno określić, do czego służą. Z kolei niejasne i skomplikowane fragmenty kodu powinny zostać przeprojektowane i przepisane[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:44:00 2001 ]--> tak[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:44:00 2001 ]--> aby same się objaśniały. Dość często zdarza się[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:44:00 2001 ]--> że komentarze stanowią dla leniwego programisty [Author ID1: at Fri Sep 1 02:37:00 2006 ]wymówkę [Author ID2: at Tue Nov 13 10:44:00 2001 ]pretekst [Author ID2: at Tue Nov 13 10:44:00 2001 ]-->dla niedbałości.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Nie sugeruję [Author ID1: at Fri Sep 1 02:37:00 2006 ]oczywiście by nigdy[Author ID2: at Tue Nov 13 10:45:00 2001 ]żeby w ogóle[Author ID2: at Tue Nov 13 10:45:00 2001 ]--> nie korzystać z komentarzy, choć oczywiście nie powinny służyć do wyjaśniania niejasnego kodu. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Zamiast tego[Author ID2: at Tue Nov 13 10:45:00 2001 ]W takim przypadku[Author ID2: at Tue Nov 13 10:45:00 2001 ]--> należy poprawić sam kod. Mówiąc krótko, pisz swoje programy dobrze, zaś komentarzy używaj w celu [Author ID1: at Fri Sep 1 02:37:00 2006 ]poprawy jego[Author ID2: at Tue Nov 13 10:45:00 2001 ]zwiększenia ich[Author ID2: at Tue Nov 13 10:45:00 2001 ]--> zrozumiałości.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.5 demonstruje użycie komentarzy[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:45:00 2001 ] i[Author ID2: at Tue Nov 13 10:45:00 2001 ]--> pokazuj[Author ID1: at Fri Sep 1 02:37:00 2006 ]ąc[Author ID2: at Tue Nov 13 10:45:00 2001 ]e,[Author ID2: at Tue Nov 13 10:45:00 2001 ]--> że nie wpływają one na działanie programu [Author ID1: at Fri Sep 1 02:37:00 2006 ]an[Author ID2: at Tue Nov 13 10:45:00 2001 ]-->i na otrzymywane wyniki.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.5. [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->HELP.cpp[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> demonstruje komentarze[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: using std::cout;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: /* to jest komentarz w stylu C[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: i rozciąga się on aż do zamykającego[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: znaku gwiazdki i ukośnika */[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: cout << "Witaj Swiecie!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: // ten komentarz kończy się wraz z końcem tej linii[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: cout << "Ten komentarz sie zakonczyl!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: // komentarze podwójnego ukośnika mogą występować w linii same[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: /* podobnie jak komentarze ukośnika i gwiazdki */[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:46:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Witaj Swiecie![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Ten komentarz sie zakonczyl![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:46:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Komentarze w liniach od 6[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> do 8[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> są całkowicie ignorowane przez kompilator, podobnie jak komentarze w liniach 10[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]-->, 13[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> oraz 14. Komentarz w linii 10[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> kończy się wraz z końcem linii, lecz komentarze w liniach 6[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> i 14[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:46:00 2001 ]--> wymagają [Author ID1: at Fri Sep 1 02:37:00 2006 ]użycia [Author ID2: at Tue Nov 13 10:46:00 2001 ]-->zamykającego znaku komentarza.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Komentarze, które informują o czymś oczywistym, są bezużyteczne. [Author ID1: at Fri Sep 1 02:37:00 2006 ]W rzeczywistości, m[Author ID2: at Tue Nov 13 10:46:00 2001 ]M[Author ID2: at Tue Nov 13 10:46:00 2001 ]-->ogą być wręcz szkodliwe, [Author ID1: at Fri Sep 1 02:37:00 2006 ]gdyż [Author ID2: at Tue Nov 13 10:47:00 2001 ]np. gdy [Author ID2: at Tue Nov 13 10:47:00 2001 ]-->kod [Author ID1: at Fri Sep 1 02:37:00 2006 ]może [Author ID2: at Tue Nov 13 10:47:00 2001 ]-->ule[Author ID1: at Fri Sep 1 02:37:00 2006 ]c[Author ID2: at Tue Nov 13 10:47:00 2001 ]gnie[Author ID2: at Tue Nov 13 10:47:00 2001 ]--> zmianie, [Author ID1: at Fri Sep 1 02:37:00 2006 ]lecz [Author ID2: at Tue Nov 13 10:47:00 2001 ]a [Author ID2: at Tue Nov 13 10:47:00 2001 ]-->programista [Author ID1: at Fri Sep 1 02:37:00 2006 ]może [Author ID2: at Tue Nov 13 10:47:00 2001 ]-->zapomni[Author ID1: at Fri Sep 1 02:37:00 2006 ][Author ID2: at Tue Nov 13 10:47:00 2001 ]--> o aktualizacji komentarza. Jednak to[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:48:00 2001 ]--> co jest oczywiste dla jednej osoby, może być niezrozumiałe dla innej, [Author ID1: at Fri Sep 1 02:37:00 2006 ]więc [Author ID2: at Tue Nov 13 10:48:00 2001 ]zatem [Author ID2: at Tue Nov 13 10:48:00 2001 ]-->musisz samodzielnie [Author ID1: at Fri Sep 1 02:37:00 2006 ]to osądzić[Author ID2: at Tue Nov 13 10:48:00 2001 ]ocenić użyteczność komentarza[Author ID2: at Tue Nov 13 10:48:00 2001 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

Mówiąc o[Author ID2: at Tue Nov 13 10:48:00 2001 ]O[Author ID2: at Tue Nov 13 10:48:00 2001 ]-->gólnie[Author ID1: at Fri Sep 1 02:37:00 2006 ] rzecz biorąc[Author ID2: at Tue Nov 13 10:48:00 2001 ]-->, komentarze powinny informować nie o tym[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:48:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->co[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> się dzieje, ale o tym, [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->dlaczego[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> tak się dzieje.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

Choć [Author ID2: at Tue Nov 13 10:49:00 2001 ]Funkcja [Author ID2: at Tue Nov 13 10:49:00 2001 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]nie [Author ID2: at Tue Nov 13 10:49:00 2001 ]-->jest [Author ID1: at Fri Sep 1 02:37:00 2006 ]zwykłą [Author ID2: at Tue Nov 13 10:49:00 2001 ]-->funkcją[Author ID1: at Fri Sep 1 02:37:00 2006 ], jednak jest to funkcja niezwykła[Author ID2: at Tue Nov 13 10:49:00 2001 ]-->. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Aby być użyteczną,[Author ID2: at Tue Nov 13 10:49:00 2001 ]Normalnie[Author ID2: at Tue Nov 13 10:49:00 2001 ]--> funkcja musi być wywołana w czasie działania programu. Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest wywoływana przez system operacyjny.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Program jest wykonywany [Author ID1: at Fri Sep 1 02:37:00 2006 ][Author ID2: at Tue Nov 13 10:49:00 2001 ]-->linia po linii[Author ID1: at Fri Sep 1 02:37:00 2006 ][Author ID2: at Tue Nov 13 10:50:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]- [Author ID2: at Tue Nov 13 10:50:00 2001 ]-->w kolejności[Author ID1: at Fri Sep 1 02:37:00 2006 ], w jakiej [Author ID2: at Tue Nov 13 10:50:00 2001 ] ich [Author ID2: at Tue Nov 13 10:50:00 2001 ]-->występ[Author ID1: at Fri Sep 1 02:37:00 2006 ]owania[Author ID2: at Tue Nov 13 10:50:00 2001 ]ują[Author ID2: at Tue Nov 13 10:50:00 2001 ]--> w kodzie źródłowym, aż do napotkania wywołania funkcji. Wtedy działanie programu [Author ID1: at Fri Sep 1 02:37:00 2006 ]się [Author ID2: at Tue Nov 13 10:50:00 2001 ][Author ID2: at Tue Nov 13 10:50:00 2001 ]-->rozgałęzia[Author ID1: at Fri Sep 1 02:37:00 2006 ]” się [Author ID2: at Tue Nov 13 10:50:00 2001 ]--> w celu wykonania funkcji. Gdy funkcja zakończy działanie, zwraca sterowanie do linii kodu następującej bezpośrednio po linii, w której funkcja została wywołana.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Dobr[Author ID1: at Fri Sep 1 02:37:00 2006 ]ą[Author ID2: at Tue Nov 13 10:51:00 2001 ]ym przykłądem jest [Author ID2: at Tue Nov 13 10:51:00 2001 ] analogią jest [Author ID2: at Tue Nov 13 10:51:00 2001 ]-->ostrzenie ołówka. Jeśli rysujesz obrazek [Author ID1: at Fri Sep 1 02:37:00 2006 ]i[Author ID2: at Tue Nov 13 10:51:00 2001 ]a[Author ID2: at Tue Nov 13 10:51:00 2001 ]--> w ołówku złamie się grafit, przestajesz rysować, idziesz naostrzyć ołówek, po czym wracasz do tego miejsca rysunku, w którym przerwałeś[Author ID1: at Fri Sep 1 02:37:00 2006 ] rysowanie[Author ID2: at Tue Nov 13 10:51:00 2001 ]-->. Gdy program wymaga wykonania usługi, może w tym celu wywołać funkcję, po czym po [Author ID1: at Fri Sep 1 02:37:00 2006 ]zakończeniu [Author ID2: at Tue Nov 13 10:51:00 2001 ]-->jej [Author ID1: at Fri Sep 1 02:37:00 2006 ]działanie [Author ID2: at Tue Nov 13 10:51:00 2001 ]zakończeniu [Author ID2: at Tue Nov 13 10:51:00 2001 ]-->podjąć działanie w tym miejscu, w którym [Author ID1: at Fri Sep 1 02:37:00 2006 ]je [Author ID2: at Tue Nov 13 10:51:00 2001 ]-->przerwał[Author ID1: at Fri Sep 1 02:37:00 2006 ] działanie[Author ID2: at Tue Nov 13 10:51:00 2001 ]-->. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Tę ideę[Author ID2: at Tue Nov 13 10:52:00 2001 ]Przebieg tego procesu[Author ID2: at Tue Nov 13 10:52:00 2001 ]--> demonstruje listing 2.6.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.6. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Demonstracja [Author ID2: at Tue Nov 13 10:52:00 2001 ]Przykład [Author ID2: at Tue Nov 13 10:52:00 2001 ]-->wywołania funkcji[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:52:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: // funkcja DemonstrationFunction[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: // wypisuje informacyjny komunikat[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: void DemonstrationFunction()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: std::cout << "Wewnatrz funkcji DemonstrationFunction\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: // funkcja main - wypisuje komunikat, następnie[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: // wywołuje funkcję DemonstrationFunction, po czym wypisuje[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: // drugi komunikat.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: std::cout << "Wewnatrz funkcji main\n" ;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: DemonstrationFunction();[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: std::cout << "Ponownie w funkcji main\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->17: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->18: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:52:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wewnatrz funkcji main[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wewnatrz funkcji DemonstrationFunction[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Ponownie w funkcji main[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 10:52:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->DemonstrationFunction()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest zdefiniowana w liniach od 5[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:52:00 2001 ]--> do 7. Gdy zostanie wywołana, wypisuje na ekranie komunikat, po czym wraca.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Linia 12[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:53:00 2001 ]--> stanowi początek rzeczywistego programu. W linii 14[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:53:00 2001 ]--> funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> wypisuje komunikat informujący[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:53:00 2001 ]--> że program znajduje się wewnątrz funkcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Po wypisaniu tego komunikatu, [Author ID1: at Fri Sep 1 02:37:00 2006 ]wywołuje funkcję [Author ID2: at Tue Nov 13 10:53:00 2001 ]DemonstrateFunction()[Author ID2: at Tue Nov 13 10:53:00 2001 ]w [Author ID2: at Tue Nov 13 10:53:00 2001 ] w [Author ID2: at Tue Nov 13 10:53:00 2001 ]-->linii 15[Author ID1: at Fri Sep 1 02:37:00 2006 ] wywołuje funkcję [Author ID2: at Tue Nov 13 10:53:00 2001 ]DemonstrateFunction()[Author ID2: at Tue Nov 13 10:53:00 2001 ]-->. To wywołanie powoduje że wykonane zostają instrukcje zawarte wewnątrz funkcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->DemonstrationFunction ()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. W tym przypadku, cała funkcja składa się z kodu w linii 6[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:53:00 2001 ]-->, [Author ID1: at Fri Sep 1 02:37:00 2006 ]który [Author ID2: at Tue Nov 13 10:54:00 2001 ]kod ten [Author ID2: at Tue Nov 13 10:54:00 2001 ]-->wypisuje kolejny komunikat. Gdy funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->DemonstrateFunction()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> kończy działanie (linia 7[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:54:00 2001 ]-->), program powraca do linii, z której ta funkcja została wywołana. W tym przypadku program wraca do linii 16[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:54:00 2001 ]-->, w której funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> wypisuje ostatnią linię komunikatu.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA Zwróć uwagę[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 10:54:00 2001 ]--> że [Author ID1: at Fri Sep 1 02:37:00 2006 ]w funkcji [Author ID2: at Tue Nov 13 10:54:00 2001 ]DemonstrationFunction[Author ID2: at Tue Nov 13 10:54:00 2001 ] [Author ID2: at Tue Nov 13 10:54:00 2001 ]-->nie ma sensu stosować instrukcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using[Author ID1: at Fri Sep 1 02:37:00 2006 ] w funkcji [Author ID2: at Tue Nov 13 10:54:00 2001 ]DemonstrationFunction[Author ID2: at Tue Nov 13 10:54:00 2001 ],[Author ID2: at Tue Nov 13 10:54:00 2001 ] [Author ID2: at Tue Nov 13 10:55:00 2001 ], [Author ID2: at Tue Nov 13 10:54:00 2001 ]-->gdyż z obiektu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> korzystamy tylko raz, w związku z czym w zupełności wystarczy zastosowanie zapisu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->std::cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. [Author ID1: at Fri Sep 1 02:37:00 2006 ]W funkcji [Author ID2: at Tue Nov 13 10:55:00 2001 ]main()[Author ID2: at Tue Nov 13 10:55:00 2001 ] m[Author ID2: at Tue Nov 13 10:55:00 2001 ]M[Author ID2: at Tue Nov 13 10:55:00 2001 ]-->ógłbym zdecydować się na skorzystanie z instrukcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->using[Author ID1: at Fri Sep 1 02:37:00 2006 ] w funkcji [Author ID2: at Tue Nov 13 10:55:00 2001 ]main()[Author ID2: at Tue Nov 13 10:55:00 2001 ],[Author ID2: at Tue Nov 13 10:55:00 2001 ],[Author ID2: at Tue Nov 13 10:55:00 2001 ]--> ale także tym razem po prostu użyłem obiektu wraz z nazwą przestrzeni nazw, tak jak pokazano w liniach 14[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 10:55:00 2001 ]--> i 16.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcje [Author ID1: at Fri Sep 1 02:37:00 2006 ]albo [Author ID2: at Tue Nov 13 10:55:00 2001 ]-->zwracają [Author ID1: at Fri Sep 1 02:37:00 2006 ]albo [Author ID2: at Tue Nov 13 10:55:00 2001 ]-->wartość, albo [Author ID1: at Fri Sep 1 02:37:00 2006 ]zwracają [Author ID2: at Tue Nov 13 10:55:00 2001 ]-->typ [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->void[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, który oznacza[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 11:20:00 2001 ]--> że nie zwracają niczego. Funkcja dodająca dwie liczby całkowite może zwracać ich sumę, [Author ID1: at Fri Sep 1 02:37:00 2006 ]i jako[Author ID2: at Tue Nov 13 11:21:00 2001 ]funkcja[Author ID2: at Tue Nov 13 11:21:00 2001 ]--> taka będzie zdefiniowana jako zwracająca wartość całkowitą. Funkcja[Author ID1: at Fri Sep 1 02:37:00 2006 ], która[Author ID2: at Tue Nov 13 11:21:00 2001 ]--> jedynie wypisuj[Author ID1: at Fri Sep 1 02:37:00 2006 ]ąca[Author ID2: at Tue Nov 13 11:21:00 2001 ]e[Author ID2: at Tue Nov 13 11:21:00 2001 ]--> komunikat[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 11:21:00 2001 ]--> nie musi niczego zwracać i [Author ID1: at Fri Sep 1 02:37:00 2006 ]jako taka [Author ID2: at Tue Nov 13 11:21:00 2001 ]-->może zostać zadeklarowana jako zwracająca typ [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->void[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja składa się z nagłówka oraz ciała. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Z kolei n[Author ID2: at Tue Nov 13 11:21:00 2001 ]N[Author ID2: at Tue Nov 13 11:21:00 2001 ]-->agłówek składa się ze zwracanego typu, nazwy funkcji oraz parametrów funkcji. Parametry funkcji umożliwiają przekazywanie wartości do funkcji. [Author ID1: at Fri Sep 1 02:37:00 2006 ]Tak więc[Author ID2: at Tue Nov 13 11:22:00 2001 ]Zatem[Author ID2: at Tue Nov 13 11:22:00 2001 ]-->, jeśli funkcja ma dodawać dwie liczby, będą one parametrami funkcji. Oto typowy nagłówek funkcji:[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->int Sum(int a, int b)[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Parametr jest deklaracją typu wartości, jaka zostanie przekazana funkcji; [Author ID1: at Fri Sep 1 02:37:00 2006 ]sama [Author ID2: at Tue Nov 13 11:22:00 2001 ]-->wartość przekazywana w wywołaniu funkcji jest nazywana argumentem. Wielu programistów używa określeń parametr i argument jako synonimów. Inni zwracają uwagę na to [Author ID1: at Fri Sep 1 02:37:00 2006 ]techniczne [Author ID2: at Tue Nov 13 11:22:00 2001 ]-->rozróżnienie. W tej książce obu terminów będziemy używać zamiennie.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Ciało funkcji składa się z otwierającego nawiasu klamrowego, [Author ID1: at Fri Sep 1 02:37:00 2006 ]braku lub [Author ID2: at Tue Nov 13 11:23:00 2001 ]-->pewnej liczby instrukcji[Author ID1: at Fri Sep 1 02:37:00 2006 ] lub ich braku[Author ID2: at Tue Nov 13 11:23:00 2001 ]-->, oraz klamrowego nawiasu zamykającego. Instrukcje określają działanie funkcji. Funkcja może zwracać wartość[Author ID1: at Fri Sep 1 02:37:00 2006 ],[Author ID2: at Tue Nov 13 11:23:00 2001 ]--> używając instrukcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->return[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Ta instrukcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]jednocześnie [Author ID2: at Tue Nov 13 11:23:00 2001 ]-->powoduje [Author ID1: at Fri Sep 1 02:37:00 2006 ]również [Author ID2: at Tue Nov 13 11:23:00 2001 ]-->wyjście z funkcji. Jeśli [Author ID1: at Fri Sep 1 02:37:00 2006 ]nie umieścisz instrukcji [Author ID2: at Tue Nov 13 11:24:00 2001 ]return[Author ID2: at Tue Nov 13 11:24:00 2001 ] [Author ID2: at Tue Nov 13 11:24:00 2001 ]-->wewnątrz funkcji[Author ID1: at Fri Sep 1 02:37:00 2006 ] nie umieścisz instrukcji [Author ID2: at Tue Nov 13 11:24:00 2001 ]return[Author ID2: at Tue Nov 13 11:24:00 2001 ]-->, funkcja automatycznie[Author ID1: at Fri Sep 1 02:37:00 2006 ] na koniec[Author ID2: at Tue Nov 13 11:24:00 2001 ]--> zwróci wartość typu [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->void[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Zwracana wartość musi mieć typ zgodny z typem zadeklarowanym w nagłówku funkcji.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->UWAGA Funkcje zostaną omówione bardziej szczegółowo w rozdziale 5., „Funkcje.” Typy, jakie mogą być [Author ID1: at Fri Sep 1 02:37:00 2006 ]przez funkcje [Author ID2: at Tue Nov 13 11:24:00 2001 ]-->zwracane[Author ID1: at Fri Sep 1 02:37:00 2006 ] przez funkcje[Author ID2: at Tue Nov 13 11:24:00 2001 ]-->, zostaną dokładniej omówione w rozdziale 3., „Zmienne i stałe.” Informacje [Author ID1: at Fri Sep 1 02:37:00 2006 ]podane [Author ID2: at Tue Nov 13 11:24:00 2001 ]zamieszczone [Author ID2: at Tue Nov 13 11:24:00 2001 ]-->w tym rozdziale mają na celu jedynie [Author ID1: at Fri Sep 1 02:37:00 2006 ]pobieżne [Author ID2: at Tue Nov 13 11:24:00 2001 ]ogólne [Author ID2: at Tue Nov 13 11:24:00 2001 ]-->zaprezentowanie funkcji, gdyż są one używane w praktycznie wszystkich programach C++.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.7 przedstawia funkcję, która otrzymuje dwa parametry całkowite i zwraca wartość całkowitą. Nie martw się na razie o składnię [Author ID1: at Fri Sep 1 02:37:00 2006 ]lub[Author ID2: at Tue Nov 13 11:25:00 2001 ]i[Author ID2: at Tue Nov 13 11:25:00 2001 ]--> sposób posługiwania się wartościami całkowitymi (na przykład [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->int x[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->); zostan[Author ID1: at Fri Sep 1 02:37:00 2006 ]ie[Author ID2: at Tue Nov 13 11:25:00 2001 ]ą[Author ID2: at Tue Nov 13 11:25:00 2001 ]--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]to [Author ID2: at Tue Nov 13 11:25:00 2001 ]one [Author ID2: at Tue Nov 13 11:25:00 2001 ]-->dokładnie omówione w rozdziale 3.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Listing 2.7. [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->FUNC.cpp[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> demonstruje prostą funkcję[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:25:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->0: #include <iostream>[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->1: int Add (int x, int y)[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->2: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->3: std::cout << "Funkcja Add() otrzymala " << x << " oraz " << y << "\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->4: return (x+y);[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->5: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->6: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->7: int main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->8: {[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->9: using std::cout;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->10: using std::cin;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->11: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->12: [Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->13: cout << "Jestem w funkcji main()!\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->14: int a, b, c;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->15: cout << "Wpisz dwie liczby: ";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->16: cin >> a;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->17: cin >> b;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->18: cout << "\nWywoluje funkcje Add()\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->19: c=Add(a,b);[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->20: cout << "\nPonownie w funkcji main().\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->21: cout << "c zostalo ustawione na " << c;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->22: cout << "\nOpuszczam program...\n\n";[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->23: return 0;[Author ID1: at Fri Sep 1 02:37:00 2006 ]

--> [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->24: }[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wynik[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 11:25:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Jestem w funkcji main()![Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wpisz dwie liczby: 3 5[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Wywoluje funkcje Add()[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja Add() otrzymala 3 oraz 5[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Ponownie w funkcji main().[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->c zostalo ustawione na 8[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Opuszczam program...[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Analiza[Author ID1: at Fri Sep 1 02:37:00 2006 ]:[Author ID2: at Tue Nov 13 11:25:00 2001 ]-->[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->Add()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest zdefiniowana w linii 1. Otrzymuje dwa parametry w postaci liczb całkowitych i zwraca wartość całkowitą. Sam program zaczyna się w linii 7. Program prosi użytkownika o dwie liczby (linie [Author ID1: at Fri Sep 1 02:37:00 2006 ]od [Author ID2: at Tue Nov 13 11:26:00 2001 ]-->15[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:25:00 2001 ]--> do 17[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:25:00 2001 ]-->). Użytkownik wpisuje liczby, oddzielając je spacją, po czym [Author ID1: at Fri Sep 1 02:37:00 2006 ]wciska [Author ID2: at Tue Nov 13 11:26:00 2001 ]naciska [Author ID2: at Tue Nov 13 11:26:00 2001 ]-->klawisz [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->Enter[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->. Funkcja [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->main()[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> w linii 19[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:25:00 2001 ]--> przekazuje funkcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->Add()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->wartości wpisane przez użytkownika.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

-->Przetwarzanie przechodzi do funkcji [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->Add()[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, która rozpoczyna się od linii 1. Parametry [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->a[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->b[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> są wypisywane, po czym sumowane. Rezultat sumowania jest zwracany w linii 4[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:26:00 2001 ]-->, po czym następuje wyjście z funkcji.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

Znajdujący się w[Author ID2: at Tue Nov 13 11:26:00 2001 ]W[Author ID2: at Tue Nov 13 11:26:00 2001 ]--> liniach 16[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:26:00 2001 ]--> i 17[Author ID1: at Fri Sep 1 02:37:00 2006 ].[Author ID2: at Tue Nov 13 11:26:00 2001 ]--> obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cin[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> służy do uzyskania liczb dla zmiennych [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->a[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> i [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->b[Author ID1: at Fri Sep 1 02:37:00 2006 ]-->, zaś obiekt [Author ID1: at Fri Sep 1 02:37:00 2006 ]-->cout[Author ID1: at Fri Sep 1 02:37:00 2006 ]--> jest używany do wypisania tych wartości na ekranie. Zmienne i inne aspekty tego programu zostaną [Author ID1: at Fri Sep 1 02:37:00 2006 ]dogłębnie [Author ID2: at Tue Nov 13 11:27:00 2001 ]szerzej [Author ID2: at Tue Nov 13 11:27:00 2001 ]-->omówione w kilku następnych rozdziałach.[Author ID1: at Fri Sep 1 02:37:00 2006 ]

W środowisku programowania,[Author ID2: at Tue Nov 13 10:18:00 2001 ] takim,[Author ID2: at Tue Nov 13 10:18:00 2001 ] jak np. Visual, pod napisem Witaj Swiecie! pojawi się jeszcze [Author ID2: at Tue Nov 13 10:18:00 2001 ]dodatkowo [Author ID2: at Tue Nov 13 10:18:00 2001 ]napis: Press any key to continue. Naciśnięcie jakiegokolwiek klawisza zamknie działanie programu HELLO.exe i usunie z ekranu jego okno (ramkę).[Author ID2: at Tue Nov 13 10:18:00 2001 ]przyp.redakcji.[Author ID2: at Tue Nov 13 10:18:00 2001 ]