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 dad7622

Browse files
Get bool example working.
1 parent 5e38c17 commit dad7622

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

‎003-std-cout-cin/01-cout.cpp‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55
// [6] (∗1) Read in a bool, a char, an int, a double, and a string.
66

77
int main() {
8-
std::cout << "\nprinting default output...\n\n";
9-
std::cout << "bool: " << true << "\n";
10-
std::cout << "char: " << "h" << "\n";
11-
std::cout << "int: " << 10 << "\n";
12-
std::cout << "double: " << 10.1 << "\n";
13-
std::cout << "string: " << "hello world" << "\n";
14-
15-
bool my_bool;
16-
char my_char;
17-
std::cout << "\ntaking user input...\n\n";
18-
std::cout << "input bool: ";
19-
std::cin >> my_bool;
20-
// std::cin.ignore();
8+
bool default_bool = true;
9+
char default_char = 'h';
10+
int default_int = 10;
11+
double default_double = 123.123;
12+
std::string default_string = "hello world!";
2113

22-
std::cout << "input char: ";
23-
std::cin >> my_char;
14+
std::cout << "\nprinting default output...\n\n";
15+
std::cout << "bool: " << default_bool << "\n";
16+
std::cout << "char: " << default_char << "\n";
17+
std::cout << "int: " << default_int << "\n";
18+
std::cout << "double: " << default_double << "\n";
19+
std::cout << "string: " << default_string << "\n";
2420

25-
std::cout << "\nprinting user input...\n\n";
26-
std::cout << "my_bool: " << my_bool << std::endl;
27-
std::cout << "my_char: " << my_char << std::endl;
2821
return 0;
2922
}

‎003-std-cout-cin/02-cout-cin.cpp‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
3+
// X.3 A Tour of C++: The Basics
4+
// [5] (∗1) Write out a bool, a char, an int, a double, and a string.
5+
// [6] (∗1) Read in a bool, a char, an int, a double, and a string.
6+
7+
int main() {
8+
bool default_bool = true;
9+
char default_char = 'h';
10+
int default_int = 10;
11+
double default_double = 123.123;
12+
std::string default_string = "hello world!";
13+
14+
std::cout << "\nprinting default output...\n\n";
15+
std::cout << "bool: " << default_bool << "\n";
16+
std::cout << "char: " << default_char << "\n";
17+
std::cout << "int: " << default_int << "\n";
18+
std::cout << "double: " << default_double << "\n";
19+
std::cout << "string: " << default_string << "\n";
20+
21+
bool my_bool;
22+
char my_char;
23+
24+
std::cout << "\ntaking user input...\n\n";
25+
std::cout << "input bool: ";
26+
std::cin >> my_bool;
27+
std::cin >> std::boolalpha >> my_bool;
28+
29+
std::cout << "input char: ";
30+
std::cin >> my_char;
31+
32+
std::cout << "\nprinting user input...\n\n";
33+
std::cout << "my_bool: " << my_bool << std::endl;
34+
std::cout << "my_char: " << my_char << std::endl;
35+
return 0;
36+
}

‎003-std-cout-cin/03-cin.cpp‎

Whitespace-only changes.

‎003-std-cout-cin/main‎

21.1 KB
Binary file not shown.

0 commit comments

Comments
(0)

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