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 9bfe372

Browse files
Minor code clean up.
1 parent 54504c1 commit 9bfe372

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ int main() {
99

1010
std::cout << "\nprinting default output...\n\n";
1111
std::cout << "bool: " << default_bool << "\n";
12+
std::cout << "bool: " << std::boolalpha << default_bool << "\n";
1213
std::cout << "char: " << default_char << "\n";
1314
std::cout << "int: " << default_int << "\n";
1415
std::cout << "double: " << default_double << "\n";

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#include <iostream>
22

33
int main() {
4-
bool default_bool = true;
5-
6-
std::cout << "\nprinting default output...\n\n";
7-
std::cout << "bool: " << default_bool << "\n";
8-
94
bool my_bool;
105
char my_char;
116

127
std::cout << "\ntaking user input...\n\n";
138
std::cout << "input bool: ";
14-
std::cin >> my_bool; // does this work for true or false?
9+
std::cin >> std::boolalpha >> my_bool; // does this work for true or false?
1510

1611
std::cout << "input char: ";
1712
std::cin >> my_char;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ int main() {
2121
std::cout << "input double: ";
2222
std::cin >> my_double;
2323

24+
std::cin.ignore();
2425
std::cout << "input string: ";
25-
std::cin >> my_string; // does this work for multiple words?
26+
// std::cin >> my_string; // does this work for multiple words?
27+
std::getline(std::cin, my_string);
2628

2729
std::cout << "\nprinting user input...\n\n";
2830
std::cout << "my_bool: " << my_bool << std::endl;

0 commit comments

Comments
(0)

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