--- id: cpp-strings-concat title: "C++ String Concatenation" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["+ operator concatenation", "append() function", "C++ 문자열 연결"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.85 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "strings", "concatenation"] raw_sources: ["https://www.w3schools.com/cpp/cpp_strings_concat.asp"] applied_in: [] github_commit: "" --- # [[C++ String Concatenation]] ## 🎯 한 줄 통찰 (One-line insight) The source reveals that a C++ `string` is actually an OBJECT with member functions — not just a data container — proven by `append()` being callable ON the string itself (`firstName.append(lastName)`) as an alternative to the `+` operator, meaning string concatenation in C++ has TWO equally valid forms (operator-based and method-based) that reflect the object-oriented nature of the type, unlike C's char arrays which have no such method-call syntax. [S1] ## 🧠 핵심 개념 (Core concepts) - **`+` operator for concatenation** — joins two strings into a new one. [S1] - **Manual spacing** — a space must be explicitly included (either inside one of the strings or as a separate `" "` literal) since concatenation doesn't add spaces automatically. [S1] - **`.append()` method** — an alternative to `+` for concatenation, callable directly on a string object, reflecting that C++ strings are objects with member functions. [S1] ## 📖 세부 내용 (Details) - Concatenation with a space baked into one string: `string firstName = "John "; string lastName = "Doe"; string fullName = firstName + lastName; cout << fullName;`. [S1] - Concatenation with an explicit space literal: `string fullName = firstName + " " + lastName;`. [S1] - Concatenation via the `.append()` method: `string fullName = firstName.append(lastName); cout << fullName;`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **문자열 연결에 자동 공백 삽입 없음**: firstName과 lastName을 그냥 더하면 공백 없이 붙기 때문에, 공백을 직접 문자열 안에 포함하거나 별도 " " 리터럴로 추가해야 한다는 점이 명시됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) 이름(firstName)과 성(lastName)을 합쳐 전체 이름(fullName)을 만드는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) Concatenating strings via the .append() method instead of the + operator (C++): ```cpp string firstName = "John "; string lastName = "Doe"; string fullName = firstName.append(lastName); cout << fullName; ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.85 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C++ Tutorial]] - **관련 개념:** [[CPP Strings Access]], [[CPP Strings Cstyle]], [[CPP Classes]] - **참조 맥락:** 문자열 연결 — C 스타일 문자열(Strings Cstyle) 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C++ String Concatenation — https://www.w3schools.com/cpp/cpp_strings_concat.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ String Concatenation" page (Astra wiki-curation, P-Reinforce v3.1 format).