Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 106cc33

Browse files
Updating to C++23
1 parent 8c571bc commit 106cc33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+232
-172
lines changed

‎headers/01-hellow.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// 01-hellow.cpp : prints a line of text to the console
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int main() {
7-
cout << "Hello, World!" << '\n';
7+
println("Hello, World!");
88
}

‎headers/01-title.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// 01-title.cpp : output the title page of a well-known book
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int main() {
7-
cout << 1+R"(
7+
print(1+R"(
88
Alice's
99
Adventures In
1010
Wonderland
1111
1212
by
1313
LEWIS CARROLL
14-
)";
14+
)");
1515
}

‎headers/02-assign.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// 02-assign.cpp : assign to local variables
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int main() {
77
int i = 1, j = 2;
88
unsigned k;
9-
cout << "(1) i = " << i << ", j = " << j << ", k = " << k << '\n';
9+
println("(1) i = {}, j = {}, k = {}", i, j, k);
1010
i = j;
1111
j = 3;
1212
k = -1;
13-
cout << "(2) i = " << i << ", j = " << j << ", k = " << k << '\n';
13+
println("(2) i = {}, j = {}, k = {}", i, j, k);
1414
}

‎headers/02-constants.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// 02-constants.cpp : introducing the const keyword
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
const double PI = 3.14159265358979;
77

88
int main() {
99
auto const APPROX_E = 3;
10-
cout << "pi is almost exactly " << PI
11-
<< "e is approximately " << APPROX_E
12-
<< '\n';
10+
println("pi is almost exactly {}, while e is approximately {}",
11+
PI, APPROX_E);
1312
}

‎headers/02-constexpr.cpp‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// 02-constexpr.cpp : introducing the constexpr keyword
22

3-
#include <iostream>
3+
#include <print>
44
#include <cmath>
55
using namespace std;
66

7-
const double PI1 = acos(-1.0);// acos is not (yet) constexpr
7+
constexpr double PI1 = acos(-1.0);
88
constexpr double PI2 = 22.0 / 7.0;
99

10-
// the following line does not compile and has been commented out
11-
//static_assert(PI1 > 3.141 && PI1 < 3.143);
10+
static_assert(PI1 > 3.141 && PI1 < 3.143);
1211
static_assert(PI2 > 3.141 && PI2 < 3.143);
1312

1413
int main() {
15-
cout << "PI1 = " << PI1 << '\n';
16-
cout << "PI2 = " << PI2 << '\n';
14+
println("PI1 = {}", PI1);
15+
println("PI2 = {}", PI2);
1716
}

‎headers/02-height.cpp‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 02-height.cpp : define the same variable name in two different namespaces
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
namespace Wonderland {
@@ -12,9 +12,7 @@ namespace VictorianEngland {
1212
}
1313

1414
int main() {
15-
cout << "Alice\'s height varies between "
16-
<< Wonderland::alice_height_m
17-
<< "m and "
18-
<< VictorianEngland::alice_height_m
19-
<< "m.\n";
15+
println("Alice\'s height varies between {}m and {}m",
16+
Wonderland::alice_height_m,
17+
VictorianEngland::alice_height_m);
2018
}

‎headers/02-references.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// 02-references.cpp : introducing l-value references
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int alice_age{ 9 };
77

88
int main() {
9-
cout << "Alice\'s age is " << alice_age << '\n';
9+
println("Alice\'s age is {}", alice_age);
1010
int& alice_age_ref = alice_age;
1111
alice_age_ref = 10;
12-
cout << "Alice\'s age is now " << alice_age << '\n';
12+
println("Alice\'s age is now {}", alice_age);
1313
}

‎headers/02-scopes.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// 02-scopes.cpp : define three variables with the same name in one program
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
auto a{ 1.5f };
77

88
int main() {
9-
cout << "(1) " << a << '\n';
9+
println("(1) {}", a);
1010
auto a{ 2u };
11-
cout << "(2) " << a << '\n';
11+
println("(2) {}", a);
1212
{
1313
auto a{ 2.5 };
14-
cout << "(3) " << a << '\n';
14+
println("(3) {}", a);
1515
}
1616
}

‎headers/02-swap.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// 02-swap.cpp : attempt to swap the values of an int and a double
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int main() {
77
int a = 1;
88
double b = 2.5;
9-
cout << "(1) a = " << a << ", b = " << b << '\n';
9+
println("(1) a = {}, b = {}", a, b);
1010
a = 2.5;
1111
b = 1;
12-
cout << "(2) a = " << a << ", b = " << b << '\n';
12+
println("(2) a = {}, b = {}", a, b);
1313
}

‎headers/02-uniform.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// 02-uniform.cpp : avoid compiler error with uniform initialization and explicit narrowing cast
22

3-
#include <iostream>
3+
#include <print>
44
using namespace std;
55

66
int main() {
77
// int c = { 2.5 }; // Error: this does NOT compile
88
int c = { static_cast<int>(2.5) }; // while this does
99
double d = { 1 }; // and so does this
10-
cout << "c = " << c << ", d = " << d << '\n';
10+
println("c = {}, d = {}", c, d);
1111
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /