-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp.html
More file actions
5508 lines (5471 loc) · 234 KB
/
cpp.html
File metadata and controls
5508 lines (5471 loc) · 234 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<link rel="icon" type="image/gif" href="/favicon.gif"/>
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png" />
<title>Lorem Ipsum</title>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<style type="text/css" id="internal-style">
@import url(hyperpolyglot.css);
</style>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<meta http-equiv="content-language" content="en"/>
</head>
<body>
<div id="container-wrap-wrap">
<div id="container-wrap">
<div id="container">
<div id="header">
<h1><a href="/"><span>Hyperpolyglot</span></a></h1>
</div>
<div id="content-wrap">
<div id="main-content">
<div id="page-title">Lorem Ipsum</div>
<div id="page-content">
<p><a name="top"></a><em>a side-by-side reference sheet</em></p>
<p><a href="#grammar-execution">grammar and execution</a> | <a href="#variables-expressions">variables and expressions</a> | <a href="#arithmetic-logic">arithmetic and logic</a> | <a href="#strings">strings</a> | <a href="#regexes">regexes</a> | <a href="#dates-time">dates and time</a> | <a href="#fixed-length-arrays">fixed-length arrays</a> | <a href="#resizable-arrays">resizable arrays</a> | <a href="#tuples">tuples</a> | <a href="#dictionaries">dictionaries</a> | <a href="#functions">functions</a> | <a href="#execution-control">execution control</a> | <a href="#exceptions">exceptions</a> | <a href="#concurrency">concurrency</a> | <a href="#file-handles">file handles</a> | <a href="#files">files</a> | <a href="#file-fmt">file formats</a> | <a href="#directories">directories</a> | <a href="#processes-environment">processes and environment</a> | <a href="#libraries-namespaces">libraries and namespaces</a> | <a href="#user-defined-types">user-defined types</a> | <a href="#generic-types">generic types</a> | <a href="#objects">objects</a> | <a href="#inheritance-polymorphism">inheritance and polymorphism</a> | <a href="#reflection">reflection</a> | <a href="#net-web">net and web</a> | <a href="#unit-tests">unit tests</a> | <a href="#debugging-profiling">debugging and profiling</a></p>
<table class="wiki-content-table">
<tr>
<th colspan="5"><a name="version"></a><a href="#version-note">version</a></th>
</tr>
<tr>
<th></th>
<th><a href="#cpp">c++</a></th>
<th><a href="#objective-c">objective c</a></th>
<th><a href="#java">java</a></th>
<th><a href="#c-sharp">c#</a></th>
</tr>
<tr>
<td><a name="version-used"></a><a href="#version-used-note">version used</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>C++11</em><br />
<em>gcc 4.8</em><br />
<em>clang 3.5</em></span></td>
<td><span style="color: gray"><em>gcc 4.2</em></span></td>
<td><span style="color: gray"><em>java 1.7</em></span></td>
<td><span style="color: gray"><em>mono 2.10 (C# 4.0)</em></span></td>
</tr>
<tr>
<td><a name="show-version"></a><a href="#show-version-note">show version</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ g++ <span style="white-space: pre-wrap;">--</span>version</td>
<td>$ gcc <span style="white-space: pre-wrap;">--</span>version</td>
<td>$ javac -version</td>
<td>$ mcs <span style="white-space: pre-wrap;">--</span>version</td>
</tr>
<tr>
<td><a name="implicit-prologue"></a><a href="#implicit-prologue-note">implicit prologue</a></td>
<td>#include <iostream<br />
#include <string<br />
<br />
using namespace std;</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="grammar-execution"></a><a href="#grammar-execution-note">grammar and execution</a></th>
</tr>
<tr>
<th></th>
<th>c++</th>
<th>objective c</th>
<th>java</th>
<th>c#</th>
</tr>
<tr>
<td><a name="hello-world"></a><a href="#hello-world-note">hello world</a></td>
<td>$ cat hello.cpp<br />
#include <iostream<br />
<br />
using namespace std;<br />
<br />
int main(int argc, char<span style="white-space: pre-wrap;">**</span> arg) {<br />
<span style="white-space: pre-wrap;"> </span>cout <span style="white-space: pre-wrap;"><<</span> "Hello, World!" <span style="white-space: pre-wrap;"><<</span> endl;<br />
}<br />
<br />
$ g++ -std=c++0x hello.cpp<br />
<br />
$ ./a.out</td>
<td>$ cat hello.m<br />
#include <stdio.h<br />
<br />
int main(int argc, char <span style="white-space: pre-wrap;">**</span>argv) {<br />
<span style="white-space: pre-wrap;"> </span>printf("Hello, World!\n");<br />
}<br />
<br />
$ gcc hello.m<br />
<br />
$ ./a.out</td>
<td>$ cat Hello.java<br />
public class Hello {<br />
<span style="white-space: pre-wrap;"> </span>public static void main(String[] args) {<br />
<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span>System.out.println("Hello, World!");<br />
<span style="white-space: pre-wrap;"> </span>}<br />
}<br />
<br />
$ javac Hello.java<br />
<br />
$ java Hello</td>
<td>$ cat hello.cs<br />
using System;<br />
<br />
public class Hello {<br />
<span style="white-space: pre-wrap;"> </span>public static void Main() {<br />
<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span>Console.WriteLine("Hello, World!");<br />
<span style="white-space: pre-wrap;"> </span>}<br />
}<br />
<br />
$ mcs hello.cs<br />
<br />
$ mono hello.exe</td>
</tr>
<tr>
<td><a name="file-suffixes"></a><a href="#file-suffixes-note">file suffixes</a><br />
<span style="color: gray"><em>source, header, object file</em></span></td>
<td>foo.cpp<br />
foo.h<br />
foo.o</td>
<td>Foo.m<br />
Foo.h<br />
Foo.o</td>
<td>Foo.java<br />
<span style="color: gray"><em>none</em></span><br />
Foo.class<br />
<br />
<span style="color: gray">Foo.java <em>must define a single top level class</em> Foo</span></td>
<td>Foo.cs<br />
<span style="color: gray"><em>none</em></span><br />
Foo.exe <span style="color: gray"><em>or</em></span> Foo.dll<br />
<br />
<span style="color: gray"><em>although files are often named after a class they contain, this is not required</em></span></td>
</tr>
<tr>
<td><a name="block-delimiters"></a><a href="#block-delimiters-note">block delimiters</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>{ }</td>
<td>{ }</td>
<td>{ }</td>
<td>{ }</td>
</tr>
<tr>
<td><a name="stmt-terminator"></a><a href="#stmt-terminator-note">statement terminator</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>;</td>
<td>;</td>
<td>;</td>
<td>;</td>
</tr>
<tr>
<td><a name="top-level-stmt"></a><a href="#top-level-stmt-note">top level statements</a></td>
<td><span style="color: gray"><em>A source file will normally have</em> #include <em>directives at the top, followed by declarations, definitions, and namespaces containing declarations and definitions.<br />
<br />
After the preprocessor has finished processing a source file, the compilation unit will only contain declarations, definitions, and namespaces at the top level.</em></span></td>
<td> </td>
<td><span style="color: gray"><em>each file contains the following elements in order:<br />
<br />
(1) optional package directive<br />
(2) zero or more import directives<br />
(3) one public class definition and zero or more private class definitions</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="eol-comment"></a><a href="#eol-comment-note">end-of-line comment</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment</span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment</span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment</span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment</span></td>
</tr>
<tr>
<td><a name="multiple-line-comment"></a><a href="#multiple-line-comment-note">multiple line comment</a></td>
<td><span style="color: gray">/* comment<br />
another comment */</span></td>
<td><span style="color: gray">/* comment<br />
another comment */</span></td>
<td><span style="color: gray">/* comment<br />
another comment */</span></td>
<td><span style="color: gray">/* comment<br />
another comment */</span></td>
</tr>
<tr>
<th colspan="5"><a name="variables-expressions"></a><a href="#variables-expressions-note">variables and expressions</a></th>
</tr>
<tr>
<th></th>
<th>c++</th>
<th>objective c</th>
<th>java</th>
<th>c#</th>
</tr>
<tr>
<td><a name="local-var"></a><a href="#local-var-note">local variable</a></td>
<td>int i;<br />
int j = 3;<br />
int k(7);</td>
<td>int i;<br />
int j = 3;</td>
<td>int i;<br />
int j = 3;</td>
<td>int i;<br />
int j = 3;</td>
</tr>
<tr>
<td><a name="uninitialized-local-var"></a><a href="#uninitialized-local-var-note">uninitialized local variable</a></td>
<td><span style="color: gray"><em>The behavior is undefined.<br />
<br />
Most implementations do not zero-initialize stack variables, so the value will be whatever happened to be in memory.</em></span></td>
<td><span style="color: gray"><em>behavior is undefined.<br />
<br />
Most implementations do not zero-initialize stack variables, so the value will be whatever happened to be in memory.</em></span></td>
<td><span style="color: gray"><em>compiler error</em></span></td>
<td><span style="color: gray"><em>compiler prevents use of uninitialized local variable</em></span></td>
</tr>
<tr>
<td><a name="global-var"></a><a href="#global-var-note">global variable</a></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> in foo.cpp and outside of any function<br />
<span style="white-space: pre-wrap;">//</span> or class definition:</span><br />
int foo = 7;<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> in bar.cpp and outside of any function<br />
<span style="white-space: pre-wrap;">//</span> or class definition:</span><br />
extern int foo;</td>
<td><span style="color: gray"><em>in</em> foo.cpp <em>outside of any function or class definition:</em></span><br />
int foo = 7;<br />
<br />
<span style="color: gray"><em>in</em> bar.cpp <em>outside of any function or class definition:</em></span><br />
extern int foo;</td>
<td><span style="color: gray"><em>foo/Foo.java:</em></span><br />
package foo;<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> globals must be declared inside a<br />
<span style="white-space: pre-wrap;">//</span> class:</span><br />
public class Foo {<br />
<span style="white-space: pre-wrap;"> </span>public static int bar;<br />
}<br />
<br />
<span style="color: gray"><em>UseFoo.java:</em></span><br />
import foo.Foo;<br />
<br />
public class UseFoo {<br />
<span style="white-space: pre-wrap;"> </span>public static void main(String[] args) {<br />
<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span>System.out.println(Foo.bar);<br />
<span style="white-space: pre-wrap;"> </span>}<br />
}</td>
<td> </td>
</tr>
<tr>
<td><a name="uninitialized-global-var"></a><a href="#uninitialized-global-var-note">uninitialized global variable</a></td>
<td><span style="color: gray"><em>Zero initialized: numeric types and pointers are set to zero. Classes, structs, and arrays have all of their members or elements zero-initialized recursively.</em></span></td>
<td> </td>
<td><span style="color: gray"><em>Zero initialized.</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="write-once-var"></a><a href="#write-once-var-note">write-once variable</a></td>
<td>const int i = 7;</td>
<td>const int i = 7;</td>
<td>final int i = 7;</td>
<td>const int i = 7;</td>
</tr>
<tr>
<td><a name="assignment"></a><a href="#assignment-note">assignment</a></td>
<td>int n;<br />
n = 3;</td>
<td> </td>
<td>int n;<br />
n = 3;</td>
<td> </td>
</tr>
<tr>
<td><a name="compound-assignment"></a><a href="#compound-assignment-note">compound assignment</a><br />
<span style="color: gray"><em>arithmetic, bit</em></span></td>
<td>+= -= *= /= %=<br />
<span style="white-space: pre-wrap;"><<= >>= </span>&= ^= |=</td>
<td> </td>
<td>+= -= *= /= %=<br />
<span style="white-space: pre-wrap;"><<= >>= </span>&= ^= |=<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">>>=</span> //is arithmetic right shift,// <span style="white-space: pre-wrap;">>>>=</span> <em>is logical right shift</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="incr-decr"></a><a href="#incr-decr-note">increment and decrement</a></td>
<td>int n = 1;<br />
int one = n++;<br />
int three = ++n;<br />
int two = <span style="white-space: pre-wrap;">--</span>n;</td>
<td> </td>
<td>int n = 1;<br />
int one = n++;<br />
int three = ++n;<br />
int two = <span style="white-space: pre-wrap;">--</span>n;</td>
<td> </td>
</tr>
<tr>
<td><a name="addr"></a><a href="#addr-note">address</a></td>
<td>int i(3);<br />
int* ip = &i;</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="dereference"></a><a href="#dereference-note">dereference</a></td>
<td>int i(3);<br />
int* ip = &i;<br />
int i2 = *ip + 1;</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="type-size"></a><a href="#type-size-note">type size</a></td>
<td>cout <span style="white-space: pre-wrap;"><<</span> sizeof(int) <span style="white-space: pre-wrap;"><<</span> endl;<br />
cout <span style="white-space: pre-wrap;"><<</span> sizeof(int*) <span style="white-space: pre-wrap;"><<</span> endl;</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="addr-arith"></a><a href="#addr-arith-note">address arithmetic</a></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="unique-ptr"></a><a href="#unique-ptr-note">unique pointer</a></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="ref-cnt-ptr"></a><a href="#ref-cnt-ptr-note">reference count pointer</a></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="weak-ptr"></a><a href="#weak-ptr-note">weak pointer</a></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="allocate-heap"></a><a href="#allocate-heap-note">allocate heap</a></td>
<td>int* ip = new int;</td>
<td>#include <stdlib.h<br />
<br />
int *ip = malloc(sizeof(int));</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> Primitive types are stack allocated.<br />
<span style="white-space: pre-wrap;">//</span> Use a wrapper class to store on the<br />
<span style="white-space: pre-wrap;">//</span> heap:</span><br />
Integer i = new Integer(0);</td>
<td>object i = 0;</td>
</tr>
<tr>
<td><a name="uninitialized-heap"></a><a href="#uninitialized-heap-note">uninitialized heap</a></td>
<td><span style="color: gray"><em>Memory allocated by the</em> new <em>operator is zero-initialized.</em></span></td>
<td> </td>
<td><span style="color: gray"><em>zero-initialized</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="free-heap"></a><a href="#free-heap-note">free heap</a></td>
<td>delete ip;</td>
<td>#include <stdlib.h<br />
<br />
free(ip);</td>
<td><span style="color: gray"><em>garbage collected</em></span></td>
<td><span style="color: gray"><em>garbage collected</em></span></td>
</tr>
<tr>
<td><a name="null"></a><a href="#null-note">null</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>NULL</td>
<td>NULL</td>
<td>null</td>
<td>null</td>
</tr>
<tr>
<td><a name="coalesce"></a><a href="#coalesce-note">coalesce</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>string s1 = s2 @</td>
<td>@@ "was null";</td>
<td>NSString *s1 = s2 @</td>
<td>@@ @"was null";</td>
<td>String s1 = s2 == null ? "was null" : s2;</td>
<td>string s1 = s2 ?? "was null";</td>
</tr>
<tr>
<th colspan="5"><a name="arithmetic-logic"></a><a href="#arithmetic-logic-note">arithmetic and logic</a></th>
</tr>
<tr>
<th></th>
<th>c++</th>
<th>objective c</th>
<th>java</th>
<th>c#</th>
</tr>
<tr>
<td><a name="boolean-type"></a><a href="#boolean-type-note">boolean type</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>bool</td>
<td>BOOL</td>
<td>boolean</td>
<td>bool</td>
</tr>
<tr>
<td><a name="true-false"></a><a href="#true-false-note">true and false</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>true false</td>
<td>YES NO</td>
<td>true false</td>
<td>true false</td>
</tr>
<tr>
<td><a name="falsehoods"></a><a href="#falsehoods-note">falsehoods</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>false 0 0.0 NULL</td>
<td>0 0.0 NULL</td>
<td>false</td>
<td>false</td>
</tr>
<tr>
<td><a name="logical-op"></a><a href="#logical-op-note">logical operators</a></td>
<td>&& @</td>
<td>@@ !<br />
and or not</td>
<td>&& @</td>
<td>@@ !</td>
<td>&& @</td>
<td>@@ !</td>
<td>&& @</td>
<td>@@ !</td>
</tr>
<tr>
<td><a name="relational-op"></a><a href="#relational-op-note">relational operators</a></td>
<td>== != < > <= >=</td>
<td>== != < > <= >=</td>
<td>== != < > <= >=</td>
<td>== != < > <= >=</td>
</tr>
<tr>
<td><a name="int-type"></a><a href="#int-type-note">integer type</a></td>
<td>signed char n1;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 1+ bytes</span><br />
short int n2;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 2+ bytes</span><br />
int n3;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 2+ bytes</span><br />
long int n4;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4+ bytes</span><br />
long long int n5;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4+ bytes</span></td>
<td>signed char <span style="color: gray"><em>1+ byte</em></span>#<br />
short int <span style="color: gray"><em>2+ bytes</em></span><br />
int <span style="color: gray"><em>2+ bytes</em></span><br />
long int <span style="color: gray"><em>4+ bytes</em></span><br />
long long int <span style="color: gray"><em>4+ bytes</em></span></td>
<td>byte n1;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 1 byte</span><br />
short n2; <span style="color: gray"><span style="white-space: pre-wrap;">//</span> 2 bytes</span><br />
int n3;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4 bytes</span><br />
long n4;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 8 bytes</span></td>
<td>sbyte <span style="color: gray"><em>1 byte</em></span><br />
short <span style="color: gray"><em>2 bytes</em></span><br />
int <span style="color: gray"><em>4 bytes</em></span><br />
long <span style="color: gray"><em>8 bytes</em></span></td>
</tr>
<tr>
<td><a name="unsigned-type"></a><a href="#unsigned-type-note">unsigned type</a></td>
<td>unsigned char n1;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 1+ bytes</span><br />
unsigned short int n2;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 2+ bytes</span><br />
unsigned int n3;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 2+ bytes</span><br />
unsigned long int n4;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4+ bytes</span><br />
unsigned long long int n5; <span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4+ bytes</span></td>
<td>unsigned char: 8+<br />
unsigned short int <span style="color: gray"><em>2 bytes+</em></span><br />
unsigned int <span style="color: gray"><em>2 bytes+</em></span><br />
unsigned long int <span style="color: gray"><em>4+ bytes</em></span><br />
unsigned long long int <span style="color: gray"><em>4+ bytes</em></span></td>
<td>char n1;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span>2 bytes</span></td>
<td>byte <span style="color: gray"><em>1 byte</em></span><br />
ushort <span style="color: gray"><em>2 bytes</em></span><br />
uint <span style="color: gray"><em>4 bytes</em></span><br />
ulong <span style="color: gray"><em>8 bytes</em></span></td>
</tr>
<tr>
<td><a name="float-type"></a><a href="#float-type-note">float type</a></td>
<td>float x1;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4 bytes</span><br />
double x2;<span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 8 bytes</span><br />
long double x3; <span style="color: gray"><span style="white-space: pre-wrap;">//</span> 16 bytes</span></td>
<td>float<br />
double<br />
long double</td>
<td>float x1;<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> 4 bytes</span><br />
double x2; <span style="color: gray"><span style="white-space: pre-wrap;">//</span> 8 bytes</span></td>
<td>float <span style="color: gray"><em>4 bytes</em></span><br />
double <span style="color: gray"><em>8 bytes</em></span></td>
</tr>
<tr>
<td><a name="fixed-type"></a><a href="#fixed-type-note">fixed type</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td>decimal <span style="color: gray"><em>12 bytes</em></span></td>
</tr>
<tr>
<td><a name="arithmetic-op"></a><a href="#arithmetic-op-note">arithmetic operators</a></td>
<td>+ - * / %</td>
<td>+ - * / %</td>
<td>+ - * / %</td>
<td>+ - * / %</td>
</tr>
<tr>
<td><a name="int-div"></a><a href="#int-div-note">integer division</a></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> evaluates to 2:</span><br />
7 / 3</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> evaluates to 2:</span><br />
7 / 3</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> evaluates to 2:</span><br />
7 / 3</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> evaluates to 2:</span><br />
7 / 3</td>
</tr>
<tr>
<td><a name="int-div-zero"></a><a href="#int-div-zero-note">integer division by zero</a></td>
<td><span style="color: gray"><em>process sent a</em></span> SIGFPE <span style="color: gray"><em>signal</em></span></td>
<td><span style="color: gray"><em>process sent a</em></span> SIGFPE <span style="color: gray"><em>signal</em></span></td>
<td><span style="color: gray"><em>throws</em></span> java.lang.ArithmeticException</td>
<td><span style="color: gray"><em>Syntax error if divisor is a constant. Otherwise throws</em></span> System.DivideByZeroException</td>
</tr>
<tr>
<td><a name="float-div"></a><a href="#float-div-note">float division</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>7 / static_cast<float>(3)</td>
<td>7 / (float)3</td>
<td>7 / (float)3</td>
<td>7 / (float)3</td>
</tr>
<tr>
<td><a name="float-div-zero"></a><a href="#float-div-zero-note">float division by zero</a><br />
<span style="color: gray"><em>dividend is positive, zero, negative</em></span></td>
<td>inf<br />
nan<br />
-inf<br />
<br />
<span style="color: gray"><em>There are no portably defined literals or constants for the above values.</em></span></td>
<td>inf<br />
nan<br />
-inf<br />
<br />
<span style="color: gray"><em>there are no portably defined literals or constants for the above values.</em></span></td>
<td>Float.POSITIVE_INFINITY<br />
Float.NaN<br />
Float.NEGATIVE_INFINITY<br />
<br />
<span style="color: gray"><em>constants with same names defined in</em></span> Double</td>
<td>float.PositiveInfinity<br />
float.NaN<br />
float.NegativeInfinity<br />
<br />
<span style="color: gray"><em>constants with same names defined in</em></span> double</td>
</tr>
<tr>
<td><a name="power"></a><a href="#power-note">power</a></td>
<td>#include <cmath> <br />
<br />
double x = pow(2.0, 32.0);</td>
<td>#include <math.h> <br />
<br />
pow(2.0, 32.0);</td>
<td>Math.pow(2.0, 32.0);</td>
<td>System.Math.Pow(2.0, 32.0);</td>
</tr>
<tr>
<td><a name="sqrt"></a><a href="#sqrt-note">sqrt</a></td>
<td>#include <cmath<br />
<br />
double x = sqrt(2);</td>
<td>#include <math.h<br />
<br />
sqrt(2)</td>
<td>Math.sqrt(2)</td>
<td>Math.Sqrt(2)</td>
</tr>
<tr>
<td><a name="sqrt-negative-one"></a><a href="#sqrt-negative-one-note">sqrt -1</a></td>
<td>nan</td>
<td>nan</td>
<td>Double.NaN</td>
<td>double.NaN</td>
</tr>
<tr>
<td><a name="transcendental-func"></a><a href="#transcendental-func-note">transcendental functions</a></td>
<td>#include <cmath<br />
<br />
exp log log2 log10<br />
sin cos tan<br />
asin acos atan<br />
atan2</td>
<td>#include <math.h<br />
<br />
exp log log2 log10<br />
sin cos tan<br />
asin acos atan<br />
atan2</td>
<td>Math.exp Math.log <span style="color: gray"><em>none</em></span> Math.log10<br />
Math.sin Math.cos Math.tan<br />
Math.asin Math.acos Math.atan<br />
Math.atan2</td>
<td>using System;<br />
<span style="white-space: pre-wrap;"> </span><br />
Math.Exp Math.Log <span style="color: gray"><em>none</em></span> Math.Log10<br />
Math.Sin Math.Cos Math.Tan<br />
Math.Asin Math.Acos Math.Atan<br />
Math.Atan2</td>
</tr>
<tr>
<td><a name="transcendental-const"></a><a href="#transcendental-const-note">transcendental constants</a></td>
<td>#include <cmath<br />
<br />
double e = M_E;<br />
double pi = M_PI;</td>
<td>#include <math.h<br />
<br />
M_E<br />
M_PI</td>
<td>Math.E<br />
Math.PI</td>
<td>System.Math.E<br />
System.Math.PI</td>
</tr>
<tr>
<td><a name="float-truncation"></a><a href="#float-truncation-note">float truncation</a><br />
<span style="color: gray"><em>towards zero, to nearest integer, towards -∞, towards ∞</em></span></td>
<td>#include <cmath<br />
<span style="white-space: pre-wrap;"> </span><br />
double x = 3.7;<br />
<span style="white-space: pre-wrap;"> </span><br />
long trnc = static_cast<long>(x);<br />
long rnd = round(x);<br />
long flr = floorl(x);<br />
long cl = ceill(x);</td>
<td>#include <math.h<br />
<span style="white-space: pre-wrap;"> </span><br />
double d = 3.77;<br />
<span style="white-space: pre-wrap;"> </span><br />
long trnc = (long)d;<br />
long rnd = round(d);<br />
long flr = floorl(d);<br />
long cl = ceill(d);</td>
<td>(long)3.77<br />
Math.round(3.77)<br />
(long)Math.floor(3.77)<br />
(long)Math.ceil(3.77)</td>
<td>using System;<br />
<span style="white-space: pre-wrap;"> </span><br />
(long)3.77<br />
Math.Round(3.77)<br />
Math.Floor(3.77)<br />
Math.Ceiling(3.77)</td>
</tr>
<tr>
<td><a name="absolute-val"></a><a href="#absolute-val-note">absolute value</a></td>
<td>#include <cmath><span style="white-space: pre-wrap;"> </span><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> fabs()</span><br />
#include <cstdlib><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> abs()</span><br />
<br />
int n = -7;<br />
int absn = abs(n);<br />
<br />
double x = -7.77;<br />
double absx = fabs(x);</td>
<td>#include <stdlib.h><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> abs()</span><br />
#include <math.h><span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">//</span> fabs()</span><br />
<br />
int i = -7;<br />
int ai = abs(i);<br />
<br />
float x = -7.77;<br />
float ax = fabs(x);</td>
<td>Math.abs(-7)<br />
Math.abs(-7.77)</td>
<td>System.Math.Abs(-7)<br />
System.Math.Abs(-7.77)</td>
</tr>
<tr>
<td><a name="int-overflow"></a><a href="#int-overflow-note">integer overflow</a></td>
<td><span style="color: gray"><em>modular arithmetic<br />
<br />
The C standard does not define behavior for signed integers, however.</em></span></td>
<td><span style="color: gray"><em>modular arithmetic<br />
<br />
The C standard does not define behavior for signed integers, however.</em></span></td>
<td><span style="color: gray"><em>modular arithmetic</em></span></td>
<td><span style="color: gray"><em>modular arithmetic</em></span></td>
</tr>
<tr>
<td><a name="float-overflow"></a><a href="#float-overflow-note">float overflow</a></td>
<td><span style="color: gray"><em>no behavior defined by standard; many implementations return</em> inf</span></td>
<td><span style="color: gray"><em>no behavior defined by standard; many implementations return</em> inf</span></td>
<td>Float.POSITIVE_INFINITY</td>
<td>float.PositiveInfinity</td>
</tr>
<tr>
<td><a name="float-limits"></a><a href="#float-limits-note">float limits</a><br />
<span style="color: gray"><em>largest finite float, smallest positive float</em></span></td>
<td>#include <cfloat<br />
<br />
FLT_MAX<br />
FLT_MIN<br />
DBL_MAX<br />
DBL_MIN<br />
LDBL_MAX<br />
LDBL_MIN</td>
<td> </td>
<td>Float.MAX_VALUE<br />
Float.MIN_VALUE<br />
Double.MAX_VALUE<br />
Double.MIN_VALUE</td>
<td>float.MaxValue<br />
float.Epsilon<br />
double.MaxValue<br />
double.Epsilon</td>
</tr>
<tr>
<td><a name="complex-construction"></a><a href="#complex-construction-note">complex construction</a></td>
<td>#include <complex<br />
<br />
complex<double> z(1.0, 2.0);</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="complex-decomposition"></a><a href="#complex-decomposition-note">complex decomposition</a><br />
<span style="color: gray"><em>real and imaginary component, argument, absolute value, conjugate</em></span></td>
<td>z.real()<br />
z.imag()<br />
arg(z)<br />
abs(z)<br />
conj(z)</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="random-num"></a><a href="#random-num-note">random number</a><br />
<span style="color: gray"><em>uniform integer, uniform float, normal float</em></span></td>
<td>#include <random<br />
<br />
default_random_engine dre;<br />
<br />
uniform_int_distribution<int> uid(0, 99);<br />
uniform_real_distribution<double<br />
<span style="white-space: pre-wrap;"> </span>urd(0.0, 1.0);<br />
normal_distribution<double> nd(0.0, 1.0);<br />
<br />
int i = uid(dre);<br />
double x = urd(dre);<br />
double y = nd(dre);</td>
<td>#include <stdlib.h<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> assuming 100 much smaller than RAND_MAX:</span><br />
int i = rand() % 100;<br />
double x = drand48();<br />
<span style="color: gray"><em>none</em></span></td>
<td>import java.util.Random;<br />
<br />
Random rnd = new Random();<br />
<br />
int i = rnd.nextInt(100);<br />
double x = rnd.nextDouble();<br />
double y = rnd.nextGaussian();</td>
<td>using System;<br />
<br />
Random rnd = new Random();<br />
<br />
int i = rnd.Next();<br />
double x = rnd.NextDouble();<br />
<span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="random-seed"></a><a href="#random-seed-note">random seed</a></td>
<td>#include <random<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> set seed in constructor:</span><br />
default_random_engine dre(17);<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> set seed of existing engine:</span><br />
dre.seed(17);</td>
<td> </td>
<td>import java.util.Random;<br />
<br />
Random rnd = new Random();<br />
<br />
rnd.setSeed(17);<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> seed can also be passed to constructor</span></td>
<td>using System;<br />
<br />
Random rnd = new Random(17);</td>
</tr>
<tr>
<td><a name="bit-op"></a><a href="#bit-op-note">bit operators</a></td>
<td><span style="white-space: pre-wrap;"> << >> & | ^ ~ </span><br />
<span style="white-space: pre-wrap;"> </span>bitand bitor compl<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">>></span> <em>is arithmetic right shift on signed integers and logical right shift on unsigned integers</em></span></td>
<td><span style="white-space: pre-wrap;"> << >> & | ^ ~ </span></td>
<td><span style="white-space: pre-wrap;"> << >> & | ^ ~ </span><br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">>></span> //is arithmetic right shift, <span style="white-space: pre-wrap;">>>></span> is logical right shift//</span>//</td>
<td><span style="white-space: pre-wrap;"> << >> & | ^ ~ </span></td>
</tr>
<tr>
<td><a name="binary-octal-hex-literals"></a><a href="#binary-octal-hex-literals-note">binary, octal, and hex literals</a></td>
<td>0b0101010<br />
052<br />
0x2a</td>
<td> </td>
<td><span style="color: gray"><em>none in Java 1.6</em></span><br />
052<br />
0x2a</td>
<td><span style="color: gray"><em>none</em></span><br />
052<br />
0x2a</td>
</tr>
<tr>
<td><a name="radix"></a><a href="#radix-note">radix</a><br />
<span style="color: gray"><em>convert integer to and from string with radix</em></span></td>
<td> </td>
<td> </td>
<td>Integer.toString(42, 7)<br />
Integer.parseInt("60", 7)</td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="strings"></a><a href="#strings-note">strings</a></th>
</tr>
<tr>
<th></th>
<th>c++</th>
<th>objective c</th>
<th>java</th>
<th>c#</th>
</tr>
<tr>
<td><a name="str-type"></a><a href="#str-type-note">string type</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>string s("lorem ipsum");<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> convert to C string:</span><br />
const char* s2 = s.c_str();</td>
<td>NSString* s = @"lorem ipsum";<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> convert to C string:</span><br />
const char* s2 = [s UTF8String];</td>
<td>java.lang.String</td>
<td>string</td>
</tr>
<tr>
<td><a name="str-literal"></a><a href="#str-literal-note">string literal</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> const char*:</span><br />
"don't say \"no\""</td>
<td>@"don't say \"no""</td>
<td>"don't say\"no\""</td>
<td>"don't say \"no\""</td>
</tr>
<tr>
<td><a name="newline-literal"></a><a href="#newline-literal-note">newline in literal</a></td>
<td><span style="color: gray"><em>Newlines in string literals are ignored.</em></span></td>
<td><span style="color: gray"><em>string literals can extend over multiple lines, but the newlines do not appear in the resulting string</em></span></td>
<td><span style="color: gray"><em>no</em></span></td>
<td><span style="color: gray"><em>string literals can extend over multiple lines, but the newlines do not appear in the resulting string</em></span></td>
</tr>
<tr>
<td><a name="str-literal-escape"></a><a href="#str-literal-escape-note">literal escapes</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>\a \b \f \n \r \t \v<br />
\\ \" \'<br />
\x<span style="color: gray"><em>hh</em></span> \<span style="color: gray"><em>o</em></span> \<span style="color: gray"><em>oo</em></span> \<span style="color: gray"><em>ooo</em></span></td>
<td>\a \b \f \n \r \t \v<br />
\\ \" \'<br />
\x<span style="color: gray"><em>hh</em></span> \<span style="color: gray"><em>o</em></span> \<span style="color: gray"><em>oo</em></span> \<span style="color: gray"><em>ooo</em></span></td>
<td>\b \f \n \r \t<br />
\\ \" \'<br />
\u<span style="color: gray"><em>hhhh</em></span> \<span style="color: gray"><em>o</em></span> \<span style="color: gray"><em>oo</em></span> \<span style="color: gray"><em>ooo</em></span></td>
<td>\a \b \f \n \r \t \v<br />
\\ \" \'<br />
\x<span style="color: gray"><em>hh</em></span> \x<span style="color: gray"><em>hhhh</em></span> \<span style="color: gray"><em>o</em></span> \<span style="color: gray"><em>oo</em></span> \<span style="color: gray"><em>ooo</em></span></td>
</tr>
<tr>
<td><a name="allocate-str"></a><a href="#allocate-str-note">allocate string</a></td>
<td>string* s = new string("hello");</td>
<td>NSString *s = @"hello";</td>
<td>String s = "hello";<br />
String t = new String(s);</td>
<td>string s = "hello";<br />
string t = string.Copy(s);</td>
</tr>
<tr>
<td><a name="mutable-str"></a><a href="#mutable-str-note">are strings mutable?</a></td>
<td>string s("bar");<br />
s[2] = 'z';</td>
<td> </td>
<td><span style="color: gray">String <em>objects are immutable.</em></span><br />
<br />
<span style="color: gray">StringBuffer <em>has</em> append(), delete(), deleteCharAt(), insert(), replace(), setCharAt().</span></td>
<td> </td>
</tr>
<tr>
<td><a name="copy-str"></a><a href="#copy-str-note">copy string</a></td>
<td>string s("bar");<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> use assignment or copy constructor:</span><br />
string s2 = s;<br />
string s3(s);<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> s contains "baz";</span><br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> s2 and s3 contain "bar":</span><br />
s[2] = 'z';</td>
<td> </td>
<td>String s = "bar";<br />
StringBuffer sb = new StringBuffer(s);<br />
sb.setCharAt(2, 'z');<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> s contains "bar"; s2 contains "baz":</span><br />
String s2 = sb.toString();</td>
<td> </td>
</tr>
<tr>
<td><a name="fmt-str"></a><a href="#fmt-str-note">format string</a></td>
<td>#include <sstream<br />
<br />
ostringstream oss;<br />
oss <span style="white-space: pre-wrap;"><<</span> "Spain: " <span style="white-space: pre-wrap;"><<</span> 7;<br />
string s(oss.str());</td>
<td>[NSString stringWithFormat:@"%@: %d", @"Spain", 7]</td>
<td>String.format("%s: %d", "Spain", 7)</td>
<td>string.Format("{0}: {1}", "Spain", 7)</td>
</tr>
<tr>
<td><a name="compare-str"></a><a href="#compare-str-note">compare strings</a></td>
<td>string s1("hello");<br />
string s2("world");<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> negative if s1 lexically before s2;<br />
<span style="white-space: pre-wrap;">//</span> zero if s1 and s2 are equal:</span><br />
int result1 = s1.compare(s2);<br />
<br />
bool result2 = s1 == s2;</td>
<td>[@"hello" compare:@"hello"]</td>
<td>"hello".compareTo("world")</td>
<td>"hello".CompareTo("world")</td>
</tr>
<tr>
<td><a name="str-concat"></a><a href="#str-concat-note">concatenate</a><br />
<span style="color: gray"><em>and append</em></span></td>
<td>string s("hello");<br />
string s2 = s + " world";<br />
s += " world";</td>
<td>NSString *s1 = @"hello";<br />
NSString *s2 = @" world";<br />
NSString *s3 = [s1 stringByAppendingString:s2];</td>
<td>"hello" + " world"</td>
<td>"hello" + " world"</td>
</tr>
<tr>
<td><a name="str-replicate"></a><a href="#str-replicate-note">replicate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>string hbar(80, '-');</td>
<td> </td>
<td>import java.util.Arrays;<br />
<br />
char[] a = new char[80];<br />
Arrays.fill(a, '-');<br />
String s = new String(a);</td>
<td> </td>
</tr>