--- id: cpp-booleans title: "C++ Booleans" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["bool type", "boolalpha manipulator", "C++ ๋ถˆ๋ฆฌ์–ธ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "booleans", "boolalpha"] raw_sources: ["https://www.w3schools.com/cpp/cpp_booleans.asp"] applied_in: [] github_commit: "" --- # [[CPP Booleans]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) `boolalpha` is explicitly NOT a data type โ€” it's an I/O stream manipulator, a persistent SETTING that changes how `cout` displays every subsequent boolean until `noboolalpha` resets it โ€” meaning printing `true`/`false` as words versus `1`/`0` isn't a per-call choice like a format specifier, but a stateful mode switch that affects ALL following boolean output on that stream. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`bool`** โ€” native C++ type; `true` (1) or `false` (0). [S1] - **Default printing shows 1/0** โ€” `cout << boolVar;` prints the integer representation by default. [S1] - **`boolalpha`** โ€” an I/O manipulator (not a type) that switches `cout` to print `true`/`false` as WORDS instead of `1`/`0`; the setting persists for all subsequent output until reset. [S1] - **`noboolalpha`** โ€” resets `cout` back to the default `1`/`0` printing behavior. [S1] - **Both styles are valid** โ€” the choice between `1`/`0` and `true`/`false` display is purely stylistic. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Default 1/0 printing: `bool isCodingFun = true; cout << isCodingFun; // 1`. [S1] - Switching to word display: `cout << boolalpha; cout << isCodingFun; // true`. [S1] - Resetting back to numeric display: `cout << noboolalpha; cout << isCodingFun; // 1`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **boolalpha๋Š” ํƒ€์ž…์ด ์•„๋‹ˆ๋ผ ์ƒํƒœ๋ฅผ ๋ฐ”๊พธ๋Š” ๋งค๋‹ˆํ“ฐ๋ ˆ์ดํ„ฐ**: ํ•œ ๋ฒˆ ์ผœ๋ฉด ์ดํ›„์˜ ๋ชจ๋“  ๋ถˆ๋ฆฌ์–ธ ์ถœ๋ ฅ์— ์ง€์†์ ์œผ๋กœ ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š” ์„ค์ •์ด๋ผ๋Š” ์ ์ด ๋ช…์‹œ์ ์œผ๋กœ ํ™•์ธ๋จ โ€” noboolalpha๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ ์ „๊นŒ์ง€ ์œ ์ง€๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” boolalpha/noboolalpha๋ฅผ ์˜ค๊ฐ€๋ฉฐ ์ถœ๋ ฅ ์Šคํƒ€์ผ์„ ์ „ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๋””๋ฒ„๊น… ์ถœ๋ ฅ์˜ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ์‹ค์ „ ํ™œ์šฉ์ด๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Switching cout's boolean display mode with boolalpha, then resetting it (C++): ```cpp bool isCodingFun = true; cout << boolalpha; // enable printing "true"/"false" cout << isCodingFun; // Outputs true cout << noboolalpha; // reset to 1/0 cout << isCodingFun; // Outputs 1 ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.86 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C++ Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CPP Math]], [[CPP Booleans Expressions]], [[C Booleans]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ๋ถˆ๋ฆฌ์–ธ ์„น์…˜ ์ฒซ ์ฑ•ํ„ฐ โ€” ๋ถˆ๋ฆฌ์–ธ ํ‘œํ˜„์‹(Booleans Expressions) ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C++ Booleans โ€” https://www.w3schools.com/cpp/cpp_booleans.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Booleans" page (Astra wiki-curation, P-Reinforce v3.1 format).