100% нашли этот документ полезным (2 голоса)
589 просмотров57 страниц

Full Modern C++ For Absolute Beginners: A Friendly Introduction To The C++ Programming Language and C++11 To C++23 Standards, 2nd Edition Slobodan Dmitrović Ebook All Chapters

Language

Загружено:

jikisobanafa
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате PDF, TXT или читать онлайн в Scribd
100% нашли этот документ полезным (2 голоса)
589 просмотров57 страниц

Full Modern C++ For Absolute Beginners: A Friendly Introduction To The C++ Programming Language and C++11 To C++23 Standards, 2nd Edition Slobodan Dmitrović Ebook All Chapters

Language

Загружено:

jikisobanafa
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате PDF, TXT или читать онлайн в Scribd
Вы находитесь на странице: 1/ 57

Download the full version of the ebook at

https://ebookmass.com

Modern C++ for Absolute Beginners: A Friendly


Introduction to the C++ Programming Language
and C++11 to C++23 Standards, 2nd Edition
Slobodan Dmitrovi
https://ebookmass.com/product/modern-c-for-
absolute-beginners-a-friendly-introduction-to-the-
c-programming-language-
and-c11-to-c23-standards-2nd-edition-slobodan-
dmitrovic/

Explore and download more ebook at https://ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Modern C for Absolute Beginners: A Friendly Introduction


to the C Programming Language 2nd Edition Slobodan
Dmitrovi■
https://ebookmass.com/product/modern-c-for-absolute-beginners-a-
friendly-introduction-to-the-c-programming-language-2nd-edition-
slobodan-dmitrovic/
testbankdeal.com

Modern C++ for Absolute Beginners 2nd Edition Slobodan


Dmitrovi■

https://ebookmass.com/product/modern-c-for-absolute-beginners-2nd-
edition-slobodan-dmitrovic/

testbankdeal.com

Modern C for Absolute Beginners - Second Edition Solbodan


Dmitrovic

https://ebookmass.com/product/modern-c-for-absolute-beginners-second-
edition-solbodan-dmitrovic/

testbankdeal.com

C Programming Language: C PROGRAMMING LANG _p2 2nd


Edition, (Ebook PDF)

https://ebookmass.com/product/c-programming-language-c-programming-
lang-_p2-2nd-edition-ebook-pdf/

testbankdeal.com
C Programming Absolute Beginner’s Guide (3rd Edition)
Perry

https://ebookmass.com/product/c-programming-absolute-beginners-
guide-3rd-edition-perry/

testbankdeal.com

C Programming for Beginners by Sett John Hafeez


Abdulmutolib

https://ebookmass.com/product/c-programming-for-beginners-by-sett-
john-hafeez-abdulmutolib/

testbankdeal.com

An Introduction to Programming through C++ Abhiram G.


Ranade

https://ebookmass.com/product/an-introduction-to-programming-through-
c-abhiram-g-ranade/

testbankdeal.com

C Programming For Dummies 2nd Edition Dan Gookin

https://ebookmass.com/product/c-programming-for-dummies-2nd-edition-
dan-gookin/

testbankdeal.com

Data Parallel C++: Programming Accelerated Systems Using


C++ and SYCL 2nd Edition James Reinders

https://ebookmass.com/product/data-parallel-c-programming-accelerated-
systems-using-c-and-sycl-2nd-edition-james-reinders/

testbankdeal.com
Modern C++ for Absolute
Beginners
A Friendly Introduction to the C++
Programming Language and C++11
to C++23 Standards
Second Edition

Slobodan Dmitrović
Modern C++ for Absolute Beginners: A Friendly Introduction to the C++
Programming Language and C++11 to C++23 Standards

Slobodan Dmitrović
Belgrade, Serbia

ISBN-13 (pbk): 978-1-4842-9273-0 ISBN-13 (electronic): 978-1-4842-9274-7


https://doi.org/10.1007/978-1-4842-9274-7

Copyright © 2023 by Slobodan Dmitrović


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: James Markham
Coordinating Editor: Gryffin Winkler
Cover image designed by eStudioCalamar
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/. For more detailed information,
please visit http://www.apress.com/source-code.
Printed on acid-free paper
To Mary Anne,
whose work is an inspiration to me.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

About the Second Edition���������������������������������������������������������������������������������������xxi

Chapter 1: Introduction�������������������������������������������������������������������������������������������� 1

Chapter 2: What Is C++?������������������������������������������������������������������������������������������ 3


C++ Standards����������������������������������������������������������������������������������������������������������������������������� 3

Chapter 3: C++ Compilers���������������������������������������������������������������������������������������� 5


Installing C++ Compilers�������������������������������������������������������������������������������������������������������������� 5
On Linux����������������������������������������������������������������������������������������������������������������������������������� 5
On Windows����������������������������������������������������������������������������������������������������������������������������� 6

Chapter 4: Our First Program����������������������������������������������������������������������������������� 7


Comments������������������������������������������������������������������������������������������������������������������������������������� 7
Hello World Example��������������������������������������������������������������������������������������������������������������������� 8

Chapter 5: Types����������������������������������������������������������������������������������������������������� 13
Fundamental Types��������������������������������������������������������������������������������������������������������������������� 13
Boolean���������������������������������������������������������������������������������������������������������������������������������� 13
Character Type����������������������������������������������������������������������������������������������������������������������� 14
Integer Types������������������������������������������������������������������������������������������������������������������������� 16
Floating-Point Types�������������������������������������������������������������������������������������������������������������� 18
Type void������������������������������������������������������������������������������������������������������������������������������� 18
Type Modifiers����������������������������������������������������������������������������������������������������������������������������� 19
Variable Declaration, Definition, and Initialization����������������������������������������������������������������������� 19

v
Table of Contents

Chapter 6: Exercises����������������������������������������������������������������������������������������������� 21
Hello World and Comments��������������������������������������������������������������������������������������������������������� 21
Declaration���������������������������������������������������������������������������������������������������������������������������������� 21
Definition������������������������������������������������������������������������������������������������������������������������������������� 22
Initialization��������������������������������������������������������������������������������������������������������������������������������� 22

Chapter 7: Operators���������������������������������������������������������������������������������������������� 25
Assignment Operator������������������������������������������������������������������������������������������������������������������ 25
Arithmetic Operators������������������������������������������������������������������������������������������������������������������� 25
Compound Assignment Operators���������������������������������������������������������������������������������������������� 27
Increment/Decrement Operators������������������������������������������������������������������������������������������������ 28

Chapter 8: Standard Input�������������������������������������������������������������������������������������� 29

Chapter 9: Exercises����������������������������������������������������������������������������������������������� 31
Standard Input���������������������������������������������������������������������������������������������������������������������������� 31
Two Inputs����������������������������������������������������������������������������������������������������������������������������������� 31
Multiple Inputs���������������������������������������������������������������������������������������������������������������������������� 32
Inputs and Arithmetic Operations����������������������������������������������������������������������������������������������� 33
Postincrement and Compound Assignment�������������������������������������������������������������������������������� 33
Integral and Floating-Point Division�������������������������������������������������������������������������������������������� 34

Chapter 10: Arrays�������������������������������������������������������������������������������������������������� 35


Chapter 11: Pointers����������������������������������������������������������������������������������������������� 37

Chapter 12: References������������������������������������������������������������������������������������������ 41

Chapter 13: Introduction to Strings������������������������������������������������������������������������ 43


Defining a String������������������������������������������������������������������������������������������������������������������������� 43
Concatenating Strings����������������������������������������������������������������������������������������������������������������� 44
Accessing Characters����������������������������������������������������������������������������������������������������������������� 45
Comparing Strings���������������������������������������������������������������������������������������������������������������������� 46
String Input��������������������������������������������������������������������������������������������������������������������������������� 47
A Pointer to a String�������������������������������������������������������������������������������������������������������������������� 48

vi
Table of Contents

Substrings����������������������������������������������������������������������������������������������������������������������������������� 48
Finding a Substring��������������������������������������������������������������������������������������������������������������������� 49

Chapter 14: Automatic Type Deduction������������������������������������������������������������������ 51

Chapter 15: Exercises��������������������������������������������������������������������������������������������� 53


Array Definition��������������������������������������������������������������������������������������������������������������������������� 53
Pointer to an Object�������������������������������������������������������������������������������������������������������������������� 54
Reference Type��������������������������������������������������������������������������������������������������������������������������� 54
Strings����������������������������������������������������������������������������������������������������������������������������������������� 55
Strings from Standard Input�������������������������������������������������������������������������������������������������������� 55
Creating a Substring������������������������������������������������������������������������������������������������������������������� 56
Finding a Single Character���������������������������������������������������������������������������������������������������������� 57
Finding a Substring��������������������������������������������������������������������������������������������������������������������� 58
Automatic Type Deduction���������������������������������������������������������������������������������������������������������� 59

Chapter 16: Statements������������������������������������������������������������������������������������������ 61


Selection Statements������������������������������������������������������������������������������������������������������������������ 61
if Statement��������������������������������������������������������������������������������������������������������������������������� 61
Conditional Expression���������������������������������������������������������������������������������������������������������� 63
The Logical Operators����������������������������������������������������������������������������������������������������������� 65
switch Statement������������������������������������������������������������������������������������������������������������������ 70
Iteration Statements������������������������������������������������������������������������������������������������������������������� 71
for Statement������������������������������������������������������������������������������������������������������������������������ 72
while Statement�������������������������������������������������������������������������������������������������������������������� 73
do Statement������������������������������������������������������������������������������������������������������������������������� 75

Chapter 17: Constants�������������������������������������������������������������������������������������������� 77

Chapter 18: Exercises��������������������������������������������������������������������������������������������� 79


A Simple if Statement����������������������������������������������������������������������������������������������������������������� 79
Logical Operators������������������������������������������������������������������������������������������������������������������������ 80
The switch Statement����������������������������������������������������������������������������������������������������������������� 81

vii
Table of Contents

The for Loop�������������������������������������������������������������������������������������������������������������������������������� 82


Array and the for Loop���������������������������������������������������������������������������������������������������������������� 83
The const Type Qualifier�������������������������������������������������������������������������������������������������������������� 83

Chapter 19: Functions�������������������������������������������������������������������������������������������� 85


Introduction��������������������������������������������������������������������������������������������������������������������������������� 85
Function Declaration������������������������������������������������������������������������������������������������������������������� 85
Function Definition���������������������������������������������������������������������������������������������������������������������� 86
Return Statement������������������������������������������������������������������������������������������������������������������������ 89
Passing Arguments��������������������������������������������������������������������������������������������������������������������� 91
Passing by Value/Copy����������������������������������������������������������������������������������������������������������� 91
Passing by Reference������������������������������������������������������������������������������������������������������������ 92
Passing by Const Reference�������������������������������������������������������������������������������������������������� 93
Function Overloading������������������������������������������������������������������������������������������������������������������ 94

Chapter 20: Exercises��������������������������������������������������������������������������������������������� 97


Function Definition���������������������������������������������������������������������������������������������������������������������� 97
Separate Declaration and Definition������������������������������������������������������������������������������������������� 97
Function Parameters������������������������������������������������������������������������������������������������������������������� 98
Passing Arguments��������������������������������������������������������������������������������������������������������������������� 99
Function Overloads��������������������������������������������������������������������������������������������������������������������� 99

Chapter 21: Scope and Lifetime���������������������������������������������������������������������������� 101


Local Scope������������������������������������������������������������������������������������������������������������������������������� 101
Block Scope������������������������������������������������������������������������������������������������������������������������������ 101
Lifetime������������������������������������������������������������������������������������������������������������������������������������� 102
Automatic Storage Duration������������������������������������������������������������������������������������������������������ 102
Dynamic Storage Duration�������������������������������������������������������������������������������������������������������� 102
Static Storage Duration������������������������������������������������������������������������������������������������������������� 103
Operators new and delete��������������������������������������������������������������������������������������������������������� 103

viii
Table of Contents

Chapter 22: Exercises������������������������������������������������������������������������������������������� 105


Automatic Storage Duration������������������������������������������������������������������������������������������������������ 105
Dynamic Storage Duration�������������������������������������������������������������������������������������������������������� 106
Automatic and Dynamic Storage Durations������������������������������������������������������������������������������ 107

Chapter 23: Classes – Introduction���������������������������������������������������������������������� 109


Data Member Fields������������������������������������������������������������������������������������������������������������������ 109
Member Functions�������������������������������������������������������������������������������������������������������������������� 110
Access Specifiers���������������������������������������������������������������������������������������������������������������������� 112
Constructors������������������������������������������������������������������������������������������������������������������������������ 116
Default Constructor������������������������������������������������������������������������������������������������������������� 116
Member Initialization����������������������������������������������������������������������������������������������������������� 119
Copy Constructor����������������������������������������������������������������������������������������������������������������� 120
Copy Assignment����������������������������������������������������������������������������������������������������������������� 123
Move Constructor���������������������������������������������������������������������������������������������������������������� 124
Move Assignment���������������������������������������������������������������������������������������������������������������� 126
Operator Overloading���������������������������������������������������������������������������������������������������������������� 128
Destructors������������������������������������������������������������������������������������������������������������������������������� 134

Chapter 24: Exercises������������������������������������������������������������������������������������������� 137


Class Instance��������������������������������������������������������������������������������������������������������������������������� 137
Class with Data Members��������������������������������������������������������������������������������������������������������� 137
Class with Member Function���������������������������������������������������������������������������������������������������� 138
Class with Data and Function Members����������������������������������������������������������������������������������� 139
Class Access Specifiers������������������������������������������������������������������������������������������������������������ 139
User-Defined Default Constructor and Destructor�������������������������������������������������������������������� 140
Constructor Initializer List��������������������������������������������������������������������������������������������������������� 141
User-Defined Copy Constructor������������������������������������������������������������������������������������������������� 143
User-Defined Move Constructor������������������������������������������������������������������������������������������������ 144
Overloading Arithmetic Operators��������������������������������������������������������������������������������������������� 145

ix
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Table of Contents

Chapter 25: Classes – Inheritance and Polymorphism����������������������������������������� 147


Inheritance�������������������������������������������������������������������������������������������������������������������������������� 147
Polymorphism��������������������������������������������������������������������������������������������������������������������������� 151

Chapter 26: Exercises������������������������������������������������������������������������������������������� 157


Inheritance�������������������������������������������������������������������������������������������������������������������������������� 157

Chapter 27: The static Specifier��������������������������������������������������������������������������� 161

Chapter 28: Templates������������������������������������������������������������������������������������������ 165


Function Templates������������������������������������������������������������������������������������������������������������������� 165
Class Templates������������������������������������������������������������������������������������������������������������������������ 167
Template Specialization������������������������������������������������������������������������������������������������������������ 171

Chapter 29: Enumerations������������������������������������������������������������������������������������ 173

Chapter 30: Exercises������������������������������������������������������������������������������������������� 177


Static Variable��������������������������������������������������������������������������������������������������������������������������� 177
Static Data Member������������������������������������������������������������������������������������������������������������������ 178
Static Member Function������������������������������������������������������������������������������������������������������������ 179
Function Template��������������������������������������������������������������������������������������������������������������������� 180
Class Template�������������������������������������������������������������������������������������������������������������������������� 181
Scoped Enums�������������������������������������������������������������������������������������������������������������������������� 182
Enums in a switch��������������������������������������������������������������������������������������������������������������������� 183

Chapter 31: Organizing Code�������������������������������������������������������������������������������� 185


Header and Source Files����������������������������������������������������������������������������������������������������������� 185
Header Guards�������������������������������������������������������������������������������������������������������������������������� 186
Namespaces����������������������������������������������������������������������������������������������������������������������������� 186

Chapter 32: Exercises������������������������������������������������������������������������������������������� 191


Header and Source Files����������������������������������������������������������������������������������������������������������� 191
Multiple Source Files���������������������������������������������������������������������������������������������������������������� 192
Namespaces����������������������������������������������������������������������������������������������������������������������������� 193
Nested Namespaces����������������������������������������������������������������������������������������������������������������� 194

x
Table of Contents

Chapter 33: Conversions�������������������������������������������������������������������������������������� 197


Implicit Conversions������������������������������������������������������������������������������������������������������������������ 197
Explicit Conversions������������������������������������������������������������������������������������������������������������������ 201

Chapter 34: Exceptions����������������������������������������������������������������������������������������� 205

Chapter 35: Smart Pointers���������������������������������������������������������������������������������� 211


Unique Pointer�������������������������������������������������������������������������������������������������������������������������� 211
Shared Pointer�������������������������������������������������������������������������������������������������������������������������� 214

Chapter 36: Exercises������������������������������������������������������������������������������������������� 217


static_cast Conversion�������������������������������������������������������������������������������������������������������������� 217
A Simple Unique Pointer����������������������������������������������������������������������������������������������������������� 218
Unique Pointer to an Object of a Class�������������������������������������������������������������������������������������� 218
Shared Pointer Exercise������������������������������������������������������������������������������������������������������������ 219
Simple Polymorphism��������������������������������������������������������������������������������������������������������������� 220
Polymorphism II������������������������������������������������������������������������������������������������������������������������ 221
Exception Handling������������������������������������������������������������������������������������������������������������������� 222
Multiple Exceptions������������������������������������������������������������������������������������������������������������������� 223

Chapter 37: Input/Output Streams������������������������������������������������������������������������ 225


File Streams������������������������������������������������������������������������������������������������������������������������������ 225
String Streams�������������������������������������������������������������������������������������������������������������������������� 229

Chapter 38: C++ Standard Library and Friends���������������������������������������������������� 235


Containers��������������������������������������������������������������������������������������������������������������������������������� 235
std::vector���������������������������������������������������������������������������������������������������������������������������� 236
std::array����������������������������������������������������������������������������������������������������������������������������� 238
std::set��������������������������������������������������������������������������������������������������������������������������������� 239
std::map������������������������������������������������������������������������������������������������������������������������������ 241
std::pair������������������������������������������������������������������������������������������������������������������������������� 244
Other Containers������������������������������������������������������������������������������������������������������������������ 245
The Range-Based for Loop������������������������������������������������������������������������������������������������������� 245
Iterators������������������������������������������������������������������������������������������������������������������������������������ 248

xi
Table of Contents

Algorithms and Utilities������������������������������������������������������������������������������������������������������������� 251


std::sort������������������������������������������������������������������������������������������������������������������������������� 252
std::find������������������������������������������������������������������������������������������������������������������������������� 254
std::copy������������������������������������������������������������������������������������������������������������������������������ 255
Min and Max Elements�������������������������������������������������������������������������������������������������������� 257
Lambda Expressions����������������������������������������������������������������������������������������������������������������� 258

Chapter 39: Exercises������������������������������������������������������������������������������������������� 267


Basic Vector������������������������������������������������������������������������������������������������������������������������������ 267
Deleting a Single Value������������������������������������������������������������������������������������������������������������� 268
Deleting a Range of Elements��������������������������������������������������������������������������������������������������� 268
Finding Elements in a Vector���������������������������������������������������������������������������������������������������� 269
Basic Set����������������������������������������������������������������������������������������������������������������������������������� 270
Set Data Manipulation��������������������������������������������������������������������������������������������������������������� 271
Set Member Functions�������������������������������������������������������������������������������������������������������������� 272
Search for Data in a Set������������������������������������������������������������������������������������������������������������ 273
Basic Map��������������������������������������������������������������������������������������������������������������������������������� 274
Inserting into a Map������������������������������������������������������������������������������������������������������������������ 275
Searching and Deleting from a Map����������������������������������������������������������������������������������������� 277
Lambda Expressions����������������������������������������������������������������������������������������������������������������� 278

Chapter 40: C++ Standards���������������������������������������������������������������������������������� 281


C++11��������������������������������������������������������������������������������������������������������������������������������������� 281
Automatic Type Deduction��������������������������������������������������������������������������������������������������� 282
Range-Based Loops������������������������������������������������������������������������������������������������������������ 282
Initializer Lists��������������������������������������������������������������������������������������������������������������������� 283
Move Semantics������������������������������������������������������������������������������������������������������������������ 284
Lambda Expressions����������������������������������������������������������������������������������������������������������� 284
The constexpr Specifier������������������������������������������������������������������������������������������������������� 285
Scoped Enumerators����������������������������������������������������������������������������������������������������������� 286
Smart Pointers��������������������������������������������������������������������������������������������������������������������� 286

xii
Table of Contents

std::unordered_set�������������������������������������������������������������������������������������������������������������� 288
std::unordered_map������������������������������������������������������������������������������������������������������������ 290
std::tuple����������������������������������������������������������������������������������������������������������������������������� 292
static_assert������������������������������������������������������������������������������������������������������������������������ 293
Introduction to Concurrency������������������������������������������������������������������������������������������������ 294
Deleted and Defaulted Functions���������������������������������������������������������������������������������������� 301
Type Aliases������������������������������������������������������������������������������������������������������������������������� 304
C++14��������������������������������������������������������������������������������������������������������������������������������������� 304
Binary Literals��������������������������������������������������������������������������������������������������������������������� 305
Digit Separators������������������������������������������������������������������������������������������������������������������� 306
Auto for Functions��������������������������������������������������������������������������������������������������������������� 306
Generic Lambdas����������������������������������������������������������������������������������������������������������������� 307
std::make_unique���������������������������������������������������������������������������������������������������������������� 307
C++17��������������������������������������������������������������������������������������������������������������������������������������� 308
Nested Namespaces������������������������������������������������������������������������������������������������������������ 308
Constexpr Lambdas������������������������������������������������������������������������������������������������������������� 309
Structured Bindings������������������������������������������������������������������������������������������������������������� 309
std::filesystem��������������������������������������������������������������������������������������������������������������������� 311
std::string_view������������������������������������������������������������������������������������������������������������������� 315
std::any�������������������������������������������������������������������������������������������������������������������������������� 317
std::variant�������������������������������������������������������������������������������������������������������������������������� 319
C++20��������������������������������������������������������������������������������������������������������������������������������������� 322
Modules������������������������������������������������������������������������������������������������������������������������������� 323
Concepts������������������������������������������������������������������������������������������������������������������������������ 325
Lambda Templates�������������������������������������������������������������������������������������������������������������� 329
[likely] and [unlikely] Attributes������������������������������������������������������������������������������������������� 330
Ranges��������������������������������������������������������������������������������������������������������������������������������� 332
Coroutines��������������������������������������������������������������������������������������������������������������������������� 336
std::span������������������������������������������������������������������������������������������������������������������������������ 337
Mathematical Constants������������������������������������������������������������������������������������������������������ 338

xiii
Table of Contents

C++23��������������������������������������������������������������������������������������������������������������������������������������� 339
Multidimensional Subscript Operator���������������������������������������������������������������������������������� 340
Literal Suffixes for size_t����������������������������������������������������������������������������������������������������� 340
The #warning Preprocessor Directive��������������������������������������������������������������������������������� 341
The std::string::contains( ) Member Function���������������������������������������������������������������������� 341
std::print������������������������������������������������������������������������������������������������������������������������������ 343

Chapter 41: Projects��������������������������������������������������������������������������������������������� 347


Project I: Book Inventory����������������������������������������������������������������������������������������������������������� 347
Project II: Book Inventory – Multiple Files��������������������������������������������������������������������������������� 362
Project III: Message Logger������������������������������������������������������������������������������������������������������� 367
Project IV: Message Logger – Multiple Files����������������������������������������������������������������������������� 386
Project V: Information System��������������������������������������������������������������������������������������������������� 392
Project VI: Information System – Multiple Files������������������������������������������������������������������������ 422

Index��������������������������������������������������������������������������������������������������������������������� 433

xiv
About the Author
Slobodan Dmitrović is a software consultant, trainer, and
author of several programming books. He is a professional
R&D software developer with two decades of experience in
the industry. Slobodan provides C++ training courses for
corporate clients and academic institutions. Connect with
Slobodan at https://www.linkedin.com/in/slobodan-
dmitrovic/.

xv
About the Technical Reviewer
Germán González-Morris is a polyglot software architect/
engineer with 20+ years of experience in the field, having
knowledge in Java, Spring, C, Julia, Python, Haskell, and
JavaScript, among others. He works for cloud (architecture)
and web distributed applications. Germán loves math
puzzles (including reading Knuth), swimming, and table
tennis. Also, he has reviewed several books including an
application container book (WebLogic) and books on
languages (C, Haskell, TypeScript, WebAssembly, Math for
coders, regexp, Julia, Algorithms). For more details, you can
visit his blog (https://devwebcl.blogspot.com/) or Twitter
account (@devwebcl).

xvii
Acknowledgments
I want to thank my friends, readers, and fellow C++ peers who have supported me in
writing the second edition of this book.
I am thankful to the entire C++ community for their help and feedback. I would
like to thank Rainer Grimm, Klaus Iglberger, Jens Weller, Bartłomiej Filipek, and
many others.
My most profound appreciation goes to S. Antonijević, Ron and Brankica, and Saša
Popović for their ongoing support.

xix
About the Second Edition
The second edition of this book is updated to include the notable features inside the
C++23 standard.
I have revised and updated numerous chapters with more relevant information and
clarification.
The second edition includes more diagrams to represent certain concepts better.
I have also added the output for all the code snippets.
The book now has a chapter entirely dedicated to various projects.
My intent with the second edition was to provide a simplified, updated, and accurate
introduction to the modern C++ programming language.

xxi
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
CHAPTER 1

Introduction
Congratulations on choosing to learn the C++ programming language, and thank you for
picking up this book. I will try to introduce you to a beautiful world of C++ to the best of
my abilities.
This book is an effort to introduce the reader to the C++ programming language in
a structured, straightforward, and friendly manner. We will use the “just enough theory
and plenty of examples” approach whenever possible.
To me, C++ is a wonderful product of the human intellect. Over the years, I have
certainly come to think of it as a thing of beauty and elegance. C++ is a language like no
other, surprising in its complexity yet wonderfully sleek and elegant in so many ways. It
is also a language that cannot be learned by guessing, one that is easy to get wrong and
challenging to get right.
In this book, we will get familiar with the language basics first. Then, we will move on
to classes, templates, and the C++ Standard Library. Once we got these covered, we will
describe the modern C++ standards in more detail.
After each section, source code exercises will help us adopt the learned material
more efficiently.
Finally, we will create a couple of source code projects. Let us get started!

1
© Slobodan Dmitrović 2023
S. Dmitrović, Modern C++ for Absolute Beginners, https://doi.org/10.1007/978-1-4842-9274-7_1
CHAPTER 2

What Is C++?
C++ is a programming language – a standardized, general-purpose, object-oriented,
compiled language. Every C++ compiler is accompanied by a set of useful functions
and containers called the C++ Standard Library. Bjarne Stroustrup created C++ as an
extension to a C programming language. Still, C++ evolved to be a completely different
programming language.
Let us emphasize this: C and C++ are two different languages. C++ started as “C with
classes,” but it is now a completely different language. So, C++ is not C; C++ is not C with
classes; it is just C++. And there is no such thing as a C/C++ programming language.
C++ is widely used for so-called systems programming as well as application
programming. C++ is a language that allows us to get down to the metal where we can
perform low-level routines if needed or soar high using abstraction mechanisms such as
templates and classes.

C++ Standards
C++ is governed by the ISO C++ standard. There are multiple ISO C++ standards listed
here in chronological order: C++03, C++11, C++14, C++17, C++20, and the upcoming
C++23 standard.
Every C++ standard, starting with C++11 onward, is referred to as “modern C++.”
And modern C++ is what we will be teaching in this book.

3
© Slobodan Dmitrović 2023
S. Dmitrović, Modern C++ for Absolute Beginners, https://doi.org/10.1007/978-1-4842-9274-7_2
Random documents with unrelated
content Scribd suggests to you:
NATIVE OF BILUCHISTAN.

Although we gather from the records of Western nations these


indications of products coming from the archipelago in the earliest
ages, yet we have no information in regard to the time that the
Hindu traders, who sailed eastward from India and purchased these
valuable articles, succeeded in planting their own religion among
those distant nations. The annals of both the Malay and Javanese
are evidently fanciful, and are generally considered unreliable for any
date previous to the introduction of Mohammedanism. Simple
chronological lists are found in Java, which refer as far back as a. d.
78; but Mr. Crawfurd says that “they are incontestable fabrications,
often differing widely from each other, and containing gaps of whole
centuries.”
The people who came from India on these early voyages were
probably of the same Talagu or Telugu nation as those now called by
the Malays “Klings” or “Kalings,” a word evidently derived from
Kalinga, the Sanscrit name for the northern part of the coast of
Coromandel. They have always continued to trade with the
peninsula, and I met them on the coast of Sumatra. Barbosa, who
saw them at Malacca when the Portuguese first arrived at that city,
thus describes them:[5] “There are many great merchants here,
Moor as well as Gentile strangers, but chiefly of the Chetis, who are
of the Coromandel coast, and have large ships, which they call
giunchi” (junks). Unlike the irregular winds that must have greatly
discouraged the early Greeks and Phœnicians from long voyages
over the Euxine and the Mediterranean, the steady monsoons of the
Bay of Bengal invited those people out to sea, and by their regular
changes promised to bring them within a year safely back to their
homes.
The United States steamship Iroquois was then lying in the roads,
and our consular agent at this port invited Captain Rodgers, our
consul from Batavia, who was there on business, and myself, to take
a ride with him out to a sugar-plantation that was under his care. In
those hot countries it is the custom to start early on pleasure
excursions, in order to avoid the scorching heat of the noonday sun.
We were therefore astir at six. Our friend had obtained a large post-
coach giving ample room for four persons, but, like all such carriages
in Java, it was so heavy and clumsy that both the driver and a
footman, who was perched up in a high box behind, had to
constantly lash our four little ponies to keep them up to even a
moderate rate of speed. Our ride of ten miles was over a well-
graded road, beautifully shaded for most of the way with tamarind-
trees. Parallel with the carriage-roads, in Java, there is always one
for buffaloes and carts, and in this manner the former are almost
always kept in prime order. Such a great double highway begins at
Angir, on the Strait of Sunda, and extends throughout the whole
length of the island to Banyuwangi, on the Strait of Bali. It passes
near Bantam and Batavia, and thence along the low lands near the
north coast to Cheribon and Samarang, thence south of Mount
Japara and so eastward. This, I was informed, was made by Marshal
Daendals, who governed Java under the French rule in 1809. There
is also a military road from Samarang to Surakarta and Jokyokarta,
where the two native princes now reside. Java also enjoys a very
complete system of telegraphic communication. On the 23d of
October, 1856, the first line, between Batavia (Weltevreden) and
Buitenzorg, was finished. Immediately after, it was so rapidly
extended that, in 1859, 1,670 English miles were completed. A
telegraphic cable was also laid in that year from Batavia up the
Straits of Banca and Rhio to Singapore; but, unfortunately, it was
broken in a short time, probably by the anchor of some vessel in
those shallow straits. After it had been repaired it was immediately
broken a second time, and in 1861 the enterprise was given up, but
now they are laying another cable across the Strait of Sunda, from
Angir to the district of Lampong; thence it will extend up the west
coast to Bencoolen and Padang, and, passing across the Padang
plateau, through Fort de Rock and Paya Kombo, come to the Strait
of Malacca, and be laid directly across to Singapore.
These Javanese ponies go well on a level or down-hill, but when
the road becomes steep they frequently stop altogether. In the hilly
parts of Java, therefore, the natives are obliged to fasten their
buffaloes to your carriage, and you must patiently wait for those
sluggish animals to take you up to the crest of the elevation.
Our road that morning led over a low country, which was devoted
wholly to rice and sugar-cane. Some of these rice-fields stretched
away on either hand as far as the eye could see, and appeared as
boundless as the ocean. Numbers of natives were scattered through
these wide fields, selecting out the ripened blades, which their
religion requires them to cut off one by one. It appears an endless
task thus to gather in all the blades over a wide plain. These are
clipped off near the top, and the rice in this state, with the hull still
on, is called “paddy.” The remaining part of the stalks is left in the
fields to enrich the soil. After each crop the ground is spaded or dug
up with a large hoe, or ploughed with a buffalo, and afterward
harrowed with a huge rake; and to aid in breaking up the clods,
water to the depth of four or five inches is let in. This is retained by
dikes which cross the fields at right angles, dividing them up into
little beds from fifty to one hundred feet square. The seed is sown
thickly in small plats at the beginning of the rainy monsoon. When
the plants are four or five inches high they are transferred to the
larger beds, which are still kept overflowed for some time. They
come to maturity about this time (June 14th), the first part of the
eastern monsoon, or dry season. Such low lands that can be thus
flooded are called sawas. Although the Javanese have built
magnificent temples, they have never invented or adopted any
apparatus that has come into common use for raising water for their
rice-fields, not even the simple means employed by the ancient
Egyptians along the hill, and which the slabs from the palaces at
Nineveh show us were also used along the Euphrates.
Only one crop is usually taken from the soil each year, unless the
fields can be readily irrigated. Manure is rarely or never used, and
yet the sawas appear as fertile as ever. The sugar-cane, however,
quickly exhausts the soil. One cause of this probably is that the
whole of every cane is taken from the field except the top and root,
while only the upper part of the rice-stalks are carried away, and the
rest is burned or allowed to decay on the ground. On this account
only one-third of a plantation is devoted to its culture at any one
time, the remaining two-thirds being planted with rice, for the
sustenance of the natives that work on that plantation. These crops
are kept rotating so that the same fields are liable to an extra drain
from sugar-cane only once in three years. On each plantation is a
village of Javanese, and several of these villages are under the
immediate management of a controleur. It is his duty to see that a
certain number of natives are at work every day, that they prepare
the ground, and put in the seed at the proper season, and take due
care of it till harvest-time.[6]
The name of the plantation we were to see was “Seroenie.” As we
neared it, several long, low, white buildings came into view, and two
or three high chimneys, pouring out dense volumes of black smoke.
By the road was a dwelling-house, and the “fabrik” was in the rear.
The canes are cut in the field and bound into bundles, each
containing twenty-five. They are then hauled to the factory in
clumsy, two-wheeled carts called pedatis, with a yoke of sapis. On
this plantation alone there are two hundred such carts. The mode
adopted here of obtaining the sugar from the cane is the same as in
our country. It is partially clarified by pouring over it, while yet in the
earthen pots in which it cools and crystallizes, a quantity of clay,
mixed with water, to the consistency of cream. The water, filtering
through, washes the crystals and makes the sugar, which up to this
time is of a dark brown, almost as white as if it had been refined.
This simple process is said to have been introduced by some one
who noticed that wherever the birds stepped on the brown sugar
with their muddy feet, in those places it became strangely white.
After all the sugar has been obtained that is possible, the cheap and
impure molasses that drains off is fermented with a small quantity of
rice. Palm-wine is then added, and from this mixture is distilled the
liquor known as “arrack,” which consequently differs little from rum.
It is considered, and no doubt rightly, the most destructive stimulant
that can be placed in the human stomach, in these hot regions.
From Java large quantities are shipped to the cold regions of
Sweden and Norway, where, if it is as injurious, its manufacturers
are, at least, not obliged to witness its poisonous effects.
After the sugar has been dried in the sun it is packed in large
cylindrical baskets of bamboo, and is ready to be taken to market
and shipped abroad.[7]
Three species of the sugar-cane are recognized by botanists: the
Saccharum sinensis of China; the Saccharum officinarum of India,
which was introduced by the Arabs into Southern Europe, and
thence transported to our own country[8] and the West Indies; and
the Saccharum violaceum of Tahiti, of which the cane of the Malay
Archipelago is probably only a variety. This view of the last species is
strengthened by the similarity of the names for it in Malaysia and
Polynesia. The Malays call it tabu; the inhabitants of the Philippines,
tubu; the Kayans of Borneo, turo; the natives of Floris, between Java
and Timur, and of Tongatabu, in Polynesia, tau; the people of Tahiti
and the Marquesas, to; and the Sandwich Islanders, ko.
It is either a native of the archipelago or was introduced in the
remotest times. The Malays used to cultivate it then as they do now,
not for the purpose of making sugar, but for its sweet juice, and
great quantities of it are seen at this time of year in all the markets,
usually cut up into short pieces and the outer layers or rind
removed. These people appear also to have been wholly ignorant of
the mode of making sugar from it, and all the sugar, or more
properly molasses, that was used, was obtained then as it is now in
the Eastern islands, namely, by boiling down the sap of the gomuti-
palm (Borassus gomuti).[9]
Sugar from cane was first brought to Europe by the Arabs, who,
as we know from the Chinese annals, frequently visited Canpu, a
port on Hanchow Bay, a short distance south of Shanghai.
Dioscorides, who lived in the early part of the first century, appears
to be the earliest writer in the West who has mentioned it. He calls it
saccharon, and says that “in consistence it was like salt.” Pliny, who
lived a little later in the same century, thus describes the article seen
in the Roman markets in his day: “Saccharon is a honey which forms
on reeds, white like gum, which crumbles under the teeth, and of
which the largest pieces are of the size of a filbert.” (Book xii., chap.
8.)
This is a perfect description of the sugar or rock-candy that I
found the Chinese manufacturing over the southern and central
parts of China during my long journeyings through that empire, and
at the same time it is not in the least applicable to the dark-brown,
crushed sugar made in India.
CHAPTER III.
THE FLORA AND FAUNA OF THE TROPICAL
EAST.

June 15th.—At 8 a. m. we left our anchorage off Surabaya, and


steamed down the Madura Strait for Macassar, the capital of
Celebes. Along the shores of the strait were many villages of
fishermen, and bamboo weirs extending out to a distance of five or
six miles from both the Java and Madura shores, and showing well
how shallow the water must be so far from land. During the
forenoon it was nearly calm, but the motion of the steamer supplied
a pleasant air. In the afternoon the wind rose to a light breeze from
the east. At noon we passed Pulo Kambing (“Goat Island”), a small,
low coral island off the south coast of Madura. Near by was a fleet of
small fishing-boats, each containing two men, who were only
protected from the broiling sun by a hat and a narrow cloth about
the loins. These boats and other larger ones farther out to sea were
extremely narrow, and provided with outriggers.
Madura receives its name from a Hindu legend, which makes it the
abode of the demigod, Baladewa. It has but one mountain-range,
and that crosses it from north to south. It is, therefore, not well
watered, and unsuitable for raising rice; and many of its people have
been obliged to migrate to the adjoining fertile shores of Java. The
coffee-tree is raised on this island, but the land is best adapted for
pasturage of the sapi, which is similar in its habits to our own neat-
cattle, and never wallows in mires and morasses like the buffalo. In
the mountains on the western part of Java, a wild species, the
banteng (Bos sondaicus), is still found. It is not regarded as the
source of the sapi, but a fertile cross is obtained from the two, and
this intermediate breed is said to be the one used on Bali and
Lombok. The sapi is found on all the islands to and including Timur,
on Borneo, Celebes, and the Spice Islands, and has been introduced
into the Philippines since their discovery, and now lives in a wild
state on Luzon, just as the cattle of the pampas in South America,
which have also descended from the domesticated breeds imported
by the Spaniards.
On the eastern end of the island, which is quite low, great
quantities of salt are obtained by evaporating water in “pans,” or
small areas enclosed with low dikes, like rice-fields. It is also
manufactured in a similar manner at several places on the north
coast of Java and on the western shore of Luzon, in the province of
Pangasinan. Generally the coasts of the islands throughout the
archipelago are either too high, or so low as to form merely muddy
morasses, which are mostly covered with a dense growth of
mangroves. In some places on the south coast of Java, sea-water is
sprinkled over sand. When this water has evaporated, the process is
repeated. The sand is then gathered, and water filtered through it
and evaporated by artificial heat. In Borneo, and among some of the
Philippines, marine plants are burned, and the lye made from their
ashes is evaporated for the sake of the salt contained in the
residuum. All through the interior, and among the mountains, houses
are built for storing it, and officials are appointed to dispose of it to
the natives. The quantity yearly manufactured for the government at
all the various places is about 40,000 koyangs, or 80,000 tons; but it
is not allowed to be shipped and used until it is five years old, and a
supply of 200,000 koyangs, or 400,000 tons, is therefore constantly
kept on hand. It is deposited in the government store-houses by
individuals at one-third of a guilder per picul. It is then transported
and sold at a great profit by the government, which monopolizes the
traffic in this necessary condiment, and obtains a large portion of its
revenue in this manner.[10]
In the afternoon we were abreast the high Tenger (i. e., wide or
spacious) mountains. Here is the famous “Sandy Sea,” a strange
thing on an island covered with such luxuriant vegetation as
everywhere appears in Java. To reach it one has to climb an old
volcano to a height of about 7,500 feet above the sea, when he
suddenly finds himself on the rim of an old crater of an irregular
elliptical form, with a minor axis of three and a half and a major axis
of four and a half miles. It is the largest crater in Java, and one of
the largest in the world. Its bottom is a level floor of sand, which in
some places is drifted by the wind like the sea, and is properly
named in Malay the Laut Pasar, or “Sandy Sea.” From this sandy
floor rise four cones, where the eruptive force has successively
found vent for a time, the greatest being evidently the oldest, and
the smallest the present active Bromo, or Brama, from the Sanscrit
Brama, the god of fire. The position and relation of this Bromo, as
compared to the surrounding crater, is entirely analogous to those
that exist between Vesuvius and Monte Somma. The outer walls of
this old mountain are of trachytic lava, and Dr. Junghuhn thinks its
history may be summed up thus: first, a period when the trachyte
was formed; this was followed by a period of trachytic lavas, then of
obsidian; fourth, of obsidian and pumice-stone; fifth, the sand
period, during which an enormous quantity of sand was thrown out,
and the present sandy floor formed with the cones rising from it;
and sixth, the present ash-period, during which only fine ashes are
thrown out from time to time, and steam and sulphurous acid gas
are constantly emitted.
The earliest descriptions of this crater represent it nearly as it is
seen at the present day; but great eruptions, similar to the one
supposed to have occurred, have been witnessed by Europeans
since they first came to Java. In the year 1772 the volcano
Papandayang, which is near the south coast of Java, and about in
Long. 108° E., threw out such an immense quantity of scoriæ and
ashes, that Dr. Junghuhn thinks a layer nearly fifty feet thick was
spread over an area within a radius of seven miles; and yet all this
was thrown out during a single night. Forty native villages were
buried beneath it, and about three thousand souls are supposed to
have perished between this single setting and rising of the sun. Dr.
Horsfield, who drew up an account of this terrible phenomenon from
the stories of the natives, wrongly supposed that “an extent of
ground, of the mountain and its environs, fifteen miles long, and full
six broad, was by this commotion swallowed up within the bowels of
the earth.”
On the 8th of July, 1822, Mount Galunggong, an old volcano, but a
few miles northeast of Papandayang, suffered a far more terrible and
destructive eruption. At noon on that day not a cloud could be seen
in the sky. The wild beasts gladly sought the friendly shades of the
dense forest; the hum of myriads of insects was hushed, and not a
sound was to be heard over the highly-cultivated declivities of this
mountain, or over the rich adjoining plain, but the dull creaking of
some native cart drawn by the sluggish buffalo. The natives, under
shelter of their rude huts, were giving themselves up to indolent
repose, when suddenly a frightful thundering was heard in the earth;
and from the top of this old volcano a dark, dense mass was seen
rising higher and higher into the air, and spreading itself out over the
clear sky with such an appalling rapidity that in a few moments the
whole landscape was shrouded in the darkness of night.
Through this thick darkness flashes of lightning gleamed in a
hundred lines, and many natives were instantly struck down to the
earth by stones falling from the sky. Then a deluge of hot water and
flowing mud rose over the rim of the old crater, and poured down
the mountain-sides, sweeping away trees and beasts and human
bodies in its seething mass. At the same moment, stones and ashes
and sand were projected to an enormous height into the air, and, as
they fell, destroyed nearly every thing within a radius of more than
twenty miles. A few villages, that were situated on high hills on the
lower declivities of the mountain, strangely escaped the surrounding
destruction by being above the streams of hot water and flowing
mud, while most of the stones and ashes and sand that were thrown
out passed completely over them, and destroyed many villages that
were farther removed from the centre of this great eruption.
The thundering was first heard at half-past one o’clock. At four the
extreme violence of the eruption was past; at five the sky began to
grow clear once more, and the same sun that at noon had shed his
life-giving light over this rich landscape, at evening was casting his
rays over the same spot then changed into a scene of utter
desolation. A second eruption followed within five days, and by that
time more than twenty thousand persons had lost their lives.
When the mountain could be ascended, a great valley was found,
which Dr. Junghuhn considers analogous to the “Val del Bove” on the
flanks of Ætna, except that a great depression among these movable
materials could not have such high, precipitous walls as are seen in
that deep gulf. This eruption was quite like that of Papandayang,
except that there was a lake in the bottom of this crater which
supplied the hot water and the mud, while all the materials thrown
out by the former volcano were in a dry state. In a similar way it is
supposed the great crater and the “Sandy Sea” of the Tenger
Mountains were formed in ancient times. On these Tenger Mountains
live a peculiar people, who speak a dialect of the Javanese, and,
despite the zealous efforts of the Mohammedan priests, still retain
their ancient Hindu religion.
In the evening, fires appeared on the hills near the sea. This was
the last we saw of Java, which, though but one-sixth of the area of
Borneo, and one-third that of Sumatra, is by far the most important
island in the archipelago. It is to the East Indies what Cuba is to the
West Indies. In each there is a great central chain of mountains.
Both shores of Cuba are opposite small bodies of water, and are
continuously low and swampy for miles, but in Java only the north
coast borders on a small sea. This shore is low, but the southern
coast, on the margin of the wide Indian Ocean that stretches away
to the Antarctic lands, is high and bold, an exception which is in
accordance with the rule that the higher elevations are opposite the
greater oceans, or, more properly, that they stand along the borders
of the ocean-beds or greatest depressions on the surface of our
globe. In Java, where the coast is rocky, the rocks are hard volcanic
basalts and trachytes, which resist the action of the sea, and the
shore-line is therefore quite regular; but in Cuba there is a fringing
of soft coral rock, which the waves quickly wear away into hundreds
of little projecting headlands and bays, and on the map the island
has a ragged border. In its geological structure, Cuba, with its
central axis of mica slates, granitic rocks, serpentines, and marbles,
has a more perfect analogue in Sumatra; for in Java the mountains,
instead of being formed by elevations of preëxisting strata, are
merely heaps of scoriæ, ashes, sand, and rock, once fluid, which
have all been ejected out of separate and distinct vents. The area of
Java is estimated at 38,250 square geographical miles; that of Cuba
at about 45,000. The length of Java is 575 geographical or 666
statute miles; that of Cuba 750 statute miles. But while the total
population of Cuba is estimated only at a million and a half, the total
population of Java and Madura is now (1865), according to official
statements, 13,917,368.[11] In 1755, after fifteen years of civil war,
the total population of Java and Madura was but 2,001,911. In a
single century, therefore, it has increased more than sixfold. This is
one of the beneficial effects of a government that can put down
rebellions and all internal wars, and encourage industry. In Cuba, of
a total area of thirty million acres, it was estimated, in 1857, that
only 48,572 were under cultivation, or, including pasturage, 218,161
acres. In Java and Madura, last year (1864), the cultivated fields and
the groves of cocoa-nut palms covered an area of 2,437,037 acres.
In Cuba, from 1853 to 1858, the yearly exports were from
27,000,000 to 32,000,000 of dollars, and the imports of about the
same value. In Java, last year, the imports amounted to 66,846,412
guilders (26,738,565 dollars); and the exports to the enormous sum
of 123,094,798 guilders (49,237,919 dollars). During 1864 twenty-
four ships arrived from the United States, of 12,610 tons’ capacity,
and three sailed for our country, of a united capacity of 2,258 tons.
[12]

Both of these great islands abound in forests, that yield large


quantities of valuable timber. Java furnishes the indestructible teak,
from which the Malays and Javanese fitted out a fleet of three
hundred vessels that besieged Malacca, two years after it had fallen
into the hands of the Portuguese. In like manner the Spaniards,
between 1724 and 1796, built with timber from the forests of Cuba
an armada that numbered one hundred and fourteen vessels,
carrying more than four thousand guns. From the Cuban forests
come the indestructible lignum-vitæ, and the beautiful mahogany.
Those jungles shelter no wild animals larger than dogs, but these in
Java are the haunts of wild oxen, tigers, one large and two small
species of leopard, the rhinoceros, two wild species of hog, and five
species of weasel. Two of the latter yield musk; and one, the Viverra
musanga, of the size of a cat, is also found in the Philippines. Six
species of deer are found on this island, and two of them, the
Cervus rufa and Cervus mantjac, are sometimes domesticated.[13]
The elephant is not found in Java, though it lives in Sumatra,
Borneo, and the peninsula. Also the wild horse of Sumatra or
Celebes does not exist in Java.
Among the more noticeable birds of Java is a beautiful species of
peacock, the Pavo spicifer. It was represented to me as quite
abundant in some places along the south coast. The natives make
very beautiful cigar-holders from fine strips of its quills. In Sumatra it
is not found, but is represented by an allied species. Of pigeons,
Java has no less than ten species. The web-footed birds are
remarkably few in species and numbers. A single duck, a teal, and
two pelicans, are said to comprise the whole number. The white
heron has already been noticed, and besides this, ten other species
have been described. One of the smallest birds in Java, and yet,
perhaps, the most important, from its great numbers, is the rice-
eater, Fringilla oryzivora, a kind of sparrow. Great flocks of these
birds are continually annoying the Malays as soon as the rice is
nearly grown. The natives have a very simple and effective mode of
driving them away. In the midst of a field a little bamboo house,
sufficient to shelter its occupant from the rain and scorching
sunshine, is perched high up on poles above the rice-stalks. Around
each field are placed rows of tall, flexible stakes, which are
connected together by a string. Many radiating lines of such stakes
extend from the house to those along the borders, and the child or
old person on watch has simply to pull any set of these lines in order
to frighten away the birds from any part of the field. There are seven
species of owls, and when the hooting of one is heard near any
house, many of the natives believe that sickness or some other
misfortune will certainly come to the inmates of that dwelling. Of
eagles and falcons, or kites, eight species are mentioned. One of the
kites is very abundant at all the anchorages, and so tame as to light
on the rigging of a ship quite near where the sailors are working.
When it has caught any offal in its long talons, it does not fly away
at once to a perch to consume the delicious morsel at its leisure, like
many birds of prey, but is so extremely greedy that it tears off pieces
with its beak and swallows them as it slowly sails along in the air.
When we begin to examine the luxuriant flora of these tropical
islands, almost the first tree that we notice by the shore is the tall,
graceful cocoa-nut palm. Occasionally it is found in small clumps, far
from the abode of man, for instead of being reared by his care, it
often comes to maturity alone, and then invites him to take up his
abode beneath its shade, by offering him at the same time its fruit
for food, and its leaves as ample thatching for the only kind of a hut
which he thinks he needs in an unchanging, tropical climate.
As it stands along the shore, it invariably inclines toward its
parent, the sea, for borne on the waves came the nut from which it
sprang, and now fully grown, it seeks to make a due return to its
ancestor by leaning over the shore and dropping into the ocean’s
bosom rich clusters of its golden fruit. Here, buoyed up by a thick
husk which is covered with a water-tight skin, the living kernel safely
floats over the calm and the stormy sea, until some friendly wave
casts it high up on a distant beach. The hot sun then quickly enables
it to thrust out its rootlets into the genial soil of coral sand and
fragments of shells, and in a few years it too is seen tossing its crest
of plumes high over the white surf, which in these sunny climes
everywhere forms the margin of the deep-blue ocean.
When the nut is young, the shell is soft and not separate from the
husk. In a short time it turns from a pale green to a light yellow. The
shell is now formed, and on its inner side is a thin layer, so soft that
it can be cut with a spoon. The natives now call it klapa muda, or
the young cocoa-nut, and they rarely eat it except in this condition.
As it grows older, the exterior becomes of a wood-color, the husk is
dry, and the shell hard and surrounded on the inside with a thick,
tough, oily, and most indigestible layer, popularly known as “the
meat” of the nut. This is the condition in which it is brought to our
markets, but the Malays seldom or never think of eating it in this
condition, and only value it for its oil. To obtain this the nut is
broken, and the meat scraped out with a knife. This pulp is then
boiled in a large pan, when the oil separates, floats on the top, and
is skimmed off. This oil is almost the only substance used for lighting
in the East, where far more lights are kept burning, in proportion to
the foreign population, than in our own temperate zone,
notwithstanding our long winter evenings, it being the custom there
for each man to light his house and veranda very brilliantly every
evening; and, if it is a festive occasion, rows of lamps must be
placed throughout his grounds.
The natives also are fond of such display. The common lamp
which they have for burning cocoa-nut oil is nothing but a glass
tumbler. This is partly filled with water, a small quantity of oil is then
poured in, and on this float two small splints that support a piece of
pith in a vertical position for a wick. When the oil is first made, it has
a sweet, rich taste, but in such a hot climate it soon becomes
extremely rancid, and that used for cooking should not be more than
two or three days old. The cool, clear water which the young nuts
contain is a most refreshing drink in those hot climates, far
preferable, according to my taste, to the warm, muddy water usually
found in all low lands within the tropics. Especially can one
appreciate it when, exposed to the burning sun on a low coral
island, he longs for a single draught from the cold sparkling streams
among his native New-England hills. He looks around him and
realizes that he is surrounded by the salt waters of the ocean—then
one of his dark attendants, divining his desire, climbs the smooth
trunk of a lofty palm, and brings down, apparently from the sky, a
nectar delicious enough for the gods.
This tree is of such importance to the natives that the Dutch
officials are required to ascertain as nearly as possible the number of
them in their several districts. In 1861 there were in Java and
Madura nearly twenty millions of these trees, or more than three to
every two natives.
Near the cocoa-nut grows the Pandanus, or “screw-pine,” which
may be correctly described as a trunk with branches at both ends.
There are two species of it widely distributed over the archipelago.
The flowers of one, the P. odoratissimus, are very fragrant and
highly prized among the Malays. In some places mats and baskets
are made from its leaves. Its woody fruit is of a spherical form, from
four to six inches in diameter, and its surface is divided with
geometrical precision by projections of a pointed pyramidal or
diamond shape.
On the low lands, back from the shore, where the soil has been
enriched with vegetable mould, the banana thrives. Unlike the
cocoa-nut tree, it is seldom seen where it has not been planted by
the hand of man. The traveller, therefore, who is worn out with his
long wanderings through the thick, almost impassable, jungles,
beholds with delight the long, green, drooping leaves of this tree. He
knows that he is near some native hut where he can find a shelter
from the hot sun, and slake his thirst with the water of the cocoa-
nut, and appease his hunger on bananas and boiled rice, a simple
and literally a frugal meal. Out of the midst of these drooping leaves
hangs down the top of the main stem, with its fruit decreasing in
size to the end. Some near the base are already changing from a
dark green to a bright golden yellow. Those are filled with delicious
juices, and they melt in your mouth like a delicately-flavored cream.
Such bananas as can be purchased in our markets have been so
bruised, and taste so little like this fruit at its home in the tropics, or
at least in the East Indian islands, that they scarcely serve to remind
one of what he has been accustomed to enjoy. The number of the
varieties of bananas and the difference between them is as great as
among apples in our own land.
Botanists call this tree the Musa paradisiaca, for its fruit is so
constantly ripening throughout the year, and is such a common
article of food, that it corresponds well to “the tree that yielded her
fruit every month,” and whose “leaves were for the healing of the
nations.”
Besides these plants, there are also seen on the low lands
Aroideæ, Amaranthaceæ, papilionaceous or leguminous plants, and
poisonous Euphorbiaceæ. The papaw (Carica papaya) thrives
luxuriantly on most soils. The natives are always fond of it, and I
found it a most palatable fruit, but the Europeans in the East
generally consider it a too coarse or common fruit to be placed on
the table. It was evidently introduced by the Portuguese and Spanish
from the West Indies, and the Malay name papaya comes from the
Spanish papayo.
At the height of one thousand feet ferns appear in very
considerable numbers, and here also the useful bamboo grows in
abundance, though it is found all the way down to the level of the
sea. Practically this is a tree, but botanically it is grass, though it
sometimes attains a height of seventy or eighty feet. It is used by
the natives for the walls of their huts. For this purpose it is split open
and pressed out flat, and other perpendicular and horizontal pieces
hold it in place. It is also used for masts, spear-handles, baskets,
vessels of all kinds, and for so many other necessary articles, that it
seems almost indispensable to them. Its outer surface becomes so
hard when partially burned, that it will take a sharp, almost cutting
edge, and the weapons of the natives were probably all made in this
manner previous to the introduction of iron. At the present time
sharpened stakes, ranjaus, of this kind are driven into the ground in
the tall grass surrounding a ladang or garden, so that any native
with naked feet (except the owner) will spear himself in attempting
to approach. I saw one man, on the island of Bum, who had
received a frightful, ragged wound in this way.
Above one thousand feet the palms, bananas, and papilionaceous
plants become fewer, and are replaced by the lofty fig or waringin,
which, with its high top and long branches, rivals the magnificent
palms by the sea-shore. The liquidambar also accompanies the fig.
Orchidaceous plants of the most wonderful forms appear on the
forest-trees, and are fastened to them so closely, that they seem to
be parts of them. Here the ferns also are seen in great variety.
Loranthaceæ and Melanostomaceæ are found in this zone. To this
region belongs the beautiful cotton-wood tree. Its trunk is seldom
more than ten or twelve inches in diameter, and rises up almost
perpendicularly thirty feet. The bark is of a light olive-green, and
remarkably smooth and fair. The limbs shoot out in whorls at right
angles to the trunk, and, as they are separated by a considerable
space, their open foliage is in strong contrast to the dark, dense
jungle out of which they usually rise. They thrive well also along the
banks of rivers. In Java these trees are frequently used as telegraph-
posts—a purpose for which they are admirably adapted on account
of their regularity. Besides, any thing but a living post would quickly
decay in these tropical lands. The fruit is a pod, and the fibrous
substance it yields is quite like cotton. I found it very suitable for
stuffing birds.
Over this region of the fig comes that of oaks and laurels.
Orchidaceous plants and melastomas are more abundant here.
Above five or six thousand feet are Rubiaceæ, heaths, and cone-
bearing trees; and from this region we pass up into one where small
ferns abound, and lichens and mosses cover the rocks and hang
from the trees. The tropical world is now beneath us, and we are in
the temperate zone.
The tops of all those volcanic mountains that are still in a state of
eruption are usually bare; and in others so large a quantity of the
sulphur they produce is washed down their sides by the rains that
the vegetation is frequently destroyed for some distance below their
summits.
One of the great privileges of a residence in the tropics is to enjoy
the delicious fruits of those regions in all their perfection. Of all
those fruits, in my opinion, the mangostin ought unquestionably to
be considered the first. This tree, a Garcinia, is about the size of a
pear-tree. Its Malay name is manggusta, whence our own, but it is
more generally known in the archipelago by the Javanese name
manggis. It flourishes in most of the islands from the south coast of
Java to Mindanao, the southernmost of the Philippines. On the
continent it yields well as far up the Peninsula of Malacca as Bankok,
in Siam, and in the interior to 16° N., but on the coast of the Bay of
Bengal only to 14° N. The attempts to introduce it into India have
failed, but the fruit is sometimes sent from Singapore after it has
been carefully coated with wax to exclude the air. In Ceylon they
have only partially succeeded in cultivating it. All the trials to raise it
in the West Indies have proved unsuccessful, so that this, the best of
all tropical fruits, is never seen on our continent. Its limited
geographical range is the more remarkable, for it is frequently seen
flourishing in the East Indian islands on all kinds of soils, and there is
reason to suppose that it has been introduced into the Philippines
within a comparatively late period, for in 1685 Dampier did not
notice it on Mindanao. The fruit is of a spherical form, and a reddish-
brown color. The outer part is a thick, tough covering containing a
white, opaque centre an inch or more in diameter. This is divided
into four or five parts, each of which usually contains a small seed.
This white part has a slightly-sweet taste, and a rich yet delicate
flavor, which is entirely peculiar to itself. It tastes perhaps more like
the white interior of a checkerberry than any other fruit in our
temperate climate. The thick covering is dried by the natives and
used for an astringent.
FRUIT MARKET.

Several fruits claim the second place in this scale. Some


Europeans would place the rambutan next the mangostin, and
others would prefer the mango or the duku. The rambutan
(Nephelium lappaceum) is nearly as large as an apple-tree. The fruit
is globular in form, and an inch or an inch and a half in diameter.
The outside is a bright-red rind, ornamented with coarse, scattered
bristles. Within is a semi-transparent pulp, of a slightly acid taste,
surrounding the seed. This tree, like the durian and the mangostin,
is wholly confined to the archipelago, and its acid fruit is most
refreshing in those hot lands. At Batavia it is so abundant in
February and March, that great quantities almost line the streets in
the market parts of the city, and small boats are seen filled to
overflowing with this bright, strawberry-colored fruit.
The mango-tree (Mangifera indica) is a large, thickly-branching
tree, with bright-green leaves. Its fruit is of an elliptical form, and
contains a flat stone of the same shape. Before it is ripe it is so
keenly acid, that it needs only to be preserved in salt water to be a
nice pickle for the table, especially with the universal curry. As it
ripens, the interior changes from green to white, and then to a
bright yellow. A tough outer skin being removed, there is seen a
soft, almost pulpy, but somewhat fibrous mass within. Some of these
fruits are extremely rich, and quite aromatic, while others have a
sharp smack of turpentine. They even vary greatly in two localities,
which may be but a few miles apart. Rumphius informs us that it
was introduced into the moluccas by the Dutch in 1655. It has also
been introduced into Zanzibar and Madagascar. When the Spaniards
first visited the Philippines it was not noticed, but now it is very
common in those islands, and considerable quantities of it are
shipped to China, where I was frequently assured it was very
delicious; but those who have tasted this or any other tropical fruit
from only one locality are by no means competent judges. At
Singapore I found some very nice ones that had been brought down
from Siam. It also flourishes in India, and Mr. Crawfurd thinks, from
the fact that the Malay and Javanese names are evidently only
corruptions of the old Sanscrit, that it was originally brought into the
archipelago from the continent, and should not be regarded as
indigenous.
The duku is another highly-esteemed fruit. The tree is tall, and
bears a loose foliage. From its trunk and limbs little branchlets grow
out, bearing in long clusters the fruit, which is about the size of a
robin’s egg. The outer coating of this fruit is thin and leathery, and of
a dull-yellow color. This contains several long seeds, surrounded by a
transparent pulp, which is sweet or pleasantly acid. The seeds
themselves are intensely bitter. The natives, however, invariably
prefer the durian to all other fruits. The Durio zibethinus is a very
large tree. Its fruit is spherical in form, six or eight inches in
diameter, and generally covered with many sharply-pointed
tubercles. This exterior is a hard shell. Within it is divided into
several parts. On breaking the shell, a seed, as large as a chestnut,
is found in each division, surrounded by a pale-yellow substance of
the consistency of thick cream, and having an odor of putrid animal
matter, so strong that a single fruit is enough to infect the air in a
large house. In the season for this fruit the whole atmosphere in the
native villages is filled with this detestable odor. The taste of this
soft, salvy, half-clotted substance is well described by Mr. Crawfurd
as like “fresh cream and filberts.” It seems paradoxical to state that
the same substance may violate a man’s sense of smell, and yet
gratify his sense of taste at the same time, but the natives certainly
are most passionately fond of it, and I once met a foreigner who
assured me that when he had once smelled this fruit he could never
be satisfied till he had eaten some of it. Its simple odor is generally
quite enough for all Europeans. It thrives well in Sumatra, Java, the
Spice Islands, and Celebes, and is found as far north as Mindanao.
On the continent forests of it exist on the Malay Peninsula, and it is
successfully raised as far north in Siam as the thirteenth or
fourteenth parallel. On the coast of the Bay of Bengal it is grown as
far north as Tenasserim, in Lat. 14° N. It flourishes well on all the
kinds of soils in this area, but all attempts have failed to introduce it
into India and also into the West Indies. Its Malay name durian
comes from duri, a thorn, and is thus applied on account of the
sharp, thorny points of the pyramidal tubercles that cover its shell.
The fact, that the Malay name is the one used wherever the fruit is
known, indicates that it originated in a Malay country, and this view
is strengthened by the circumstance that, while I was crossing
Sumatra, I passed through large forests mostly composed of these
trees in the high lands near the sources of the Palembang River.
Another far-famed fruit is the bread-fruit. It grows on a tree, the
Artocarpus incisa, which attains a height of forty or fifty feet. It will
be noticed at once by the stranger, on account of its enormous,
sharply-lobed leaves, which are frequently a foot wide and a foot
and a half long. The fruit has nearly the form of a melon, and is
attached by its stem directly to the trunk or limbs. It is regarded of
little value by the Malays, but farther east, in the Society Islands,
and other parts of the South Sea, it furnishes the natives with their
chief sustenance. Just before it is ripe it is cut into slices and fried,
and eaten with a thick, black molasses, obtained by boiling down the
sap of the gomuti-palm. When prepared in this manner it tastes
somewhat like a potato, except that it is very fibrous. The seeds of
this fruit in the South Sea are said, when roasted, to be as nice as
chestnuts, but I never saw the Malays make any use of them. From
the Pacific Islands it has been introduced into the West Indies and
tropical America. Another species of this genus, the A. integrifolia,
bears the huge “jack-fruit,” which very closely resembles the bread-
fruit. Sometimes it attains a weight of nearly seventy-five pounds, so
that one is a good load for a coolie. The only part which the natives
eat is a sweet, pulpy substance enveloping each seed.
June 16th.—This morning the gigantic mountain on Bali, Gunung
Agung, or “The Great Mountain,” towered up abeam of us against
the southern sky. According to Mr. Crawford it attains an elevation of
twelve thousand three hundred and seventy-nine feet, or four
hundred and thirty-three feet higher than the far-famed Peak of
Teneriffe.
These mountains are only a continuation of the chain which
traverses Java, and Bali may be regarded as almost a part of Java,
as it has quite the same flora and fauna, and is only separated from
that island by a narrow strait. Here the Asiatic fauna of Sumatra,
Borneo, and Java reaches its most eastern boundary. On Lombok,
the next island eastward, a wholly different fauna is seen, having
well-marked affinities with that of Australia. According to the
traditions of the Javanese, Sumatra, Java, Bali, Lombok, and
Sumbawa, were all formerly united, and afterward separated into
nine different parts, and when three thousand rainy reasons shall
have passed away they will be reunited. The dates of these
separations are given as follows:
Palembang (the eastern end of Sumatra) from Java, a. d. 1192.
Bali from Balembangan (the eastern end of Java), a. d. 1282.
Lombok from Sumbawa, a. d. 1350.
All these dates are absurdly recent, and besides, the separations,
in all probability, did not occur in the order given above. When we
compare the fauna of the continent with that of Sumatra, Java, and
Borneo, we find that Sumatra has the greatest number of species
identical with those of the Peninsula of Malacca; that Borneo has a
somewhat less proportion, and that Java has the largest number
peculiar to itself. Thence we conclude that Java was the first of these
islands that was separated from the continent, that Borneo was next
detached, and Sumatra at the latest period. Bali was probably
separated from Java at a yet more recent date.
Mr. Sclater was the first to notice the fact that the dividing line
between the Asiatic fauna and that of Australia must be drawn down
the Strait of Macassar, and this observation has only been confirmed
by all who have collected in those regions since. Mr. A. R. Wallace
further ascertained that this line should be continued southward,
through the Strait of Lombok, between the island of that name and
Bali. He visited the latter island, and thus contrasts its birds with
those of Lombok: “In Bali we have barbets, fruit-thrushes, and
woodpeckers; on passing over to Lombok these are seen no more,
but we have an abundance of cockatoos, honeysuckers, and brush-
turkeys (Megapodiidæ), which are equally unknown in Bali, and
every island farther west. The strait here is but fifteen miles wide, so
that we may pass in two hours from one great division of the earth
to another, differing as essentially in their animal life as Europe does
from America.”
The royal tiger of Sumatra and Java is also found on that part of
Bali nearest Java, but neither this nor any other feline animal exists
on Lombok.
Monkeys, squirrels, civets, and others are seen west of this
dividing line, but not east of it. Wild hogs are distributed over all the
larger islands from Sumatra to New Guinea, and even occur as far
eastward as Ceram. The flora of these islands is not divided in this
manner, but maintains quite the same character from the northern
end of Timur to the eastern end of Java.
In 1845 Mr. Earl pointed out the fact that Java, Sumatra, and
Borneo, all stand on a plateau which is only covered by a shallow
sea. They therefore not only were formerly connected, as the
similarity of their faunæ shows, but are at the present day, and a
line on the map, which indicates where the sea reaches a depth of
one hundred fathoms, shows exactly where the great basins of the
Pacific and Indian Oceans really begin. Northward this line unites the
Philippines to Asia, and also proves that Formosa, the Lew-Chew and
Japanese Islands, and the Kuriles, are all parts of the same great
continent. Judging from what is known of their fauna, Mr. Wallace
thinks the separation of the Philippines from the continent occurred
before that of Java, and since that epoch they have undergone very
considerable changes in their physical geography.
In 1478, when the Hindu religion was driven out of Java, it took
refuge in Bali, where it exists to the present day. The natives here,
as in India, are divided into four castes. The first and highest
includes only the priests; the second, the soldiers; the third, the
merchants; and the fourth, and lowest, comprises the common
laborers. According to Mr. Crawford, who visited the island, the wives
of the soldiers frequently sacrifice themselves by stabbing with the
kris, and the body is afterward burned, and “with the princes, the
sacrifice of one or two women is indispensable.” The high mountains
on Bali contain a number of lakes or tarns, which supply many
streams, and the natives are thus enabled to irrigate their land so
completely, that about twenty thousand tons of rice are annually
exported to other parts of the archipelago, after a population of
nearly three-quarters of a million is supplied. In 1861 Java had only
a population of three hundred and twenty-five to a square mile,
while Bali was supposed to have nearly five hundred, and it is
probably the most densely populated island in these seas at the
present time.
The Hindu religion also prevails over a part of Lombok. On this
island a huge mountain rises up, according to the trigonometrical
measurements of Baron van Carnbée, to a height of twelve thousand
three hundred and sixty English feet, and probably overtops every
other lofty peak in the whole archipelago.
CHAPTER IV.
CELEBES AND TIMUR.

June 18th.—We anchored this evening close in to the coast of


Celebes on a shallow plateau, which is really only a slightly-
submerged part of the island itself. This word Celebes is not of
native origin, and was probably introduced by the Portuguese, who
were the earliest Europeans that visited this island. It first appears in
the historical and descriptive writings of De Barros,[14] who informs
us that it was not discovered until 1525, fourteen years after the
Portuguese first came to the Moluccas; but at that time they were
only anxious to find the regions where the clove and the nutmeg
grew. Afterward they were induced to search for this island from the
rumors that came of the gold found here; and, indeed, to this day,
gold is obtained in the northern and southwestern peninsulas. At
first, Celebes was supposed to consist of many islands, and this
belief appears to have given it a name in a plural form. It consists of
a small, irregular, central area and four long limbs or peninsulas, and
De Cauto[15] very aptly describes it as “resembling in form a huge
grasshopper.” Two of these peninsulas extend to the south, and are
separated from each other by the Gulf of Boni: one takes an easterly
direction, and the other stretches away six degrees to the north and
northeast. In the southwest peninsula, which is the only one that
has been completely explored, two languages are spoken—the
Mangkasara, in the native tongue, or Mangkasa, in the Malay (of
which word, “Macassar,” the name of the Dutch capital, is only a
corruption), and the Wugi or Bugi, which was originally more
particularly limited to the coast of the Gulf of Boni. North of
Macassar, in the most western part of the island, is another people—
the Mandhar—who speak another language. On the island of Buton,
which ought to be considered a part of the peninsula east of the Gulf
of Boni, another language is spoken. The eastern peninsula is
unexplored. The northern contains the people speaking the
Gorontalo and the Menado languages.
The primitive religion of most of these natives is supposed to have
been some form of Hinduism. De Cauto says: “They have no
temples, but pray looking up to the skies with their heads raised,”
which he regards as conclusive evidence that “they had a knowledge
of the true God.” According to the records of the Macassar people,
[16] the Mohammedan religion was first taught them by a native of
Menangkabau, a province on the plateau in the interior of Sumatra,
north of the present city of Padang. This occurred just before the
arrival of the Portuguese in 1525, and the native annals say that the
doctrine of the false Prophet and of Christianity were presented to
the prince of Macassar at the same time, and that his advisers
pressed him to accept Mohammedanism, because “God would not
allow error to arrive before truth.”
In the interior live a people called by the coast tribes Turaju, who
are represented as head-hunters, and even cannibals. Barbosa[17]
makes a similar statement in regard to all the natives of this island in
his time. He says, when they came to the Moluccas to trade, they
were accustomed to ask the king of those islands to kindly deliver up
to them the persons he had condemned to death, that they might
gratify their palates on the bodies of such unfortunates, “as if asking
for a hog.”
As we steamed up the coast to Macassar, the mountains in the
interior came grandly into view. They appear much more connected
into chains than in Java. One of them, Lompo-batung, rises to a
height of eight thousand two hundred feet above the sea, and is
probably the loftiest peak on the whole island.
The harbor of Macassar is formed by a long, curving coral reef,
with its convex side from the shore. At a few places this reef rises
above the surface of the water and forms low islands; but, in the
heavy gales of the western monsoon, the sea frequently breaks over
it into the road with such violence as to drive most of the native
praus on shore. Near it were fleets of fishing-boats, and this was the
first place in these tropical seas where I found a fish that, according
to my taste, was as nice as those which come from the cold waters
that bathe our New-England shores.
In the road were many praus of forty or fifty tons’ burden, and
some even twice as large. In the beginning of the western monsoon
they go in great numbers to the Arru Islands, the principal
rendezvous[18] for the people of Ceram, Goram, the Ki Islands,
Tenimber, Baba, and the adjacent coast of New Guinea. Mr. Wallace,
who was particularly seeking the birds of paradise, went in one of
these rude vessels to the Arrus, a distance of one thousand miles.
When Mr. Jukes was at Port Essington, in January, 1845, two of
these praus were there. One had made the passage from Macassar
in ten, and another in fifteen days. But, on these long voyages,
many never return. In the last of the month a third came into that
port and reported that four others, more than had arrived safely, had
just foundered during a heavy gale, and that the crew of only one
was salved. Many go every year to the islands off the eastern end of
Ceram and to the neighboring coast of Papua, and sometimes along
its northern shores to Geelvink Bay. These long voyages indicate that
the Bugis are now what the Malays were when the Portuguese first
came to the East, namely, the great navigators and traders of the
archipelago. They carry to all these localities English calicoes and
cotton goods of their own manufacture, also Chinese gongs and
large quantities of arrack. They bring in return tortoise-shell,
mother-of-pearl shell, pearls, birds of paradise, and tripang, which
appears to be the common Malay name for all kinds of Holothurians,
or “sea-cucumbers.” These latter animals abound on every coral reef
throughout the archipelago, just above and below low-water level.
As many as twenty different sorts are recognized of perhaps half as
many species. That kind is considered the most valuable which is
found on the banks of coral sand which are bare, or nearly bare, at
low tide, and are covered with a short, green sea-weed. After the
animals are collected, the intestines are removed, and they are
boiled in sea-water, in some places with the leaves of the papaw,
and in others with the bark of a mangrove-tree which gives them a
bright-red color. After they have been boiled, they are buried in the
ground till the next day, when they are spread out to dry in the sun.
Sometimes they are not buried in the ground, but dried at once on a
framework of bamboo-splints over a fire. They are now ready to be
shipped to China, the only market for this disgusting article. There
the Celestials make of them one of their many favorite soups. It is
said that the Chinese cooks boil them some time with pieces of
sugar-cane to partially neutralize their rank flavor. Many are also
gathered in the Gulf of Siam and sent up the China Sea. Mr.
Crawfurd has been unable to discover any mention of tripang by the
Portuguese writers, and this he regards as one proof, among others,
“that the Chinese, who chiefly carry on this trade, had not yet
settled in the archipelago when the Portuguese first appeared in it.”
There are yearly shipped from Macassar some fourteen thousand
piculs of this article, of a value of nearly six hundred thousand
dollars! A few cargoes, chiefly of coffee, from Menado and the
interior, are exported each year directly to Europe, but ships usually
have to go to China for a return-freight. In 1847 Macassar was made
a free port, in imitation of Singapore.
Our steamer came alongside a well-built iron pier, the only one of
any kind I had yet seen in the East. Though the mail then came but
once a month, there seemed to be no great excitement. A small
group of soldiers, with red and yellow epaulets, came down and
looked on in a most unconcerned manner, while a number of coolies
gathered and began carrying the cargo on shore—for trucks and
drays are modern innovations that have not yet appeared in these
distant regions, not even to any considerable degree in Batavia. The
sea-water here is remarkably pure and clear. As we were hauling in
to the pier, several boys kept swimming round and round the ship,
and shouting out, “Képing tuam! képing tuan!” that is, “A small piece
of money, sir! a small piece of money, sir!” and I found that when I
threw a copper coin as large as a cent, so that it would strike the
water edgewise, even at a distance of ten feet from them, some one

Вам также может понравиться