--- id: cpp-new-lines title: "C++ New Lines" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["\\n vs endl", "escape sequence", "C++ μ€„λ°”κΏˆ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "newline", "endl"] raw_sources: ["https://www.w3schools.com/cpp/cpp_new_lines.asp"] applied_in: [] github_commit: "" --- # [[CPP New Lines]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C++ offers TWO distinct ways to create a new line β€” the escape sequence `\n` and the `endl` manipulator β€” and the source explicitly states both do the same visible job but `\n` is "most used," meaning `endl` is a genuine C++-specific alternative to `\n` that C's `printf()` never had, since manipulators (objects that modify stream behavior via `<<`) are a C++-only I/O stream concept. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`\n`** β€” the escape sequence for a new line, same concept as in C; can be embedded inside a string OR appended via a separate `<<` operator. [S1] - **`endl`** β€” a C++-specific stream MANIPULATOR that also breaks lines, inserted via `<<` like a regular value. [S1] - **Doubled `\n` produces a blank line** β€” same behavior as C. [S1] - **`\n` is more commonly used** than `endl`, despite both being valid. [S1] - **Other escape sequences** β€” `\t` (tab), `\\` (backslash), `\"` (double quote) β€” same set as C. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Newline embedded in a string: `cout << "Hello World! \n"; cout << "I am learning C++";`. [S1] - Newline appended via a separate `<<`: `cout << "Hello World!" << "\n";`. [S1] - Blank line via doubled `\n`: `cout << "Hello World!" << "\n\n";`. [S1] - Using the `endl` manipulator instead: `cout << "Hello World!" << endl; cout << "I am learning C++";`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **endl은 C++ 고유의 슀트림 μ‘°μž‘μž**: \nκ³Ό 같은 κ²°κ³Όλ₯Ό λ‚΄μ§€λ§Œ, endl은 <<둜 μ‚½μž…λ˜λŠ” 슀트림 λ§€λ‹ˆν“°λ ˆμ΄ν„°λΌλŠ” C++만의 κ°œλ…μœΌλ‘œ, C의 printf()μ—λŠ” λŒ€μ‘ κ°œλ…μ΄ μ—†λ‹€λŠ” 점이 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” \nκ³Ό endl 쀑 \n이 더 널리 μ“°μΈλ‹€λŠ” 점이 μ‹€μ „ μ½”λ“œ μŠ€νƒ€μΌ μ„ νƒμ˜ κΈ°μ€€μœΌλ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Using the endl manipulator as an alternative to \n (C++): ```cpp cout << "Hello World!" << endl; cout << "I am learning C++"; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Output Numbers]], [[CPP Variables]], [[C Newline]] - **μ°Έμ‘° λ§₯락:** Basics μ„Ήμ…˜ λ§ˆμ§€λ§‰ β€” λ³€μˆ˜(Variables) μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ New Lines β€” https://www.w3schools.com/cpp/cpp_new_lines.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ New Lines" page (Astra wiki-curation, P-Reinforce v3.1 format).