---
id: cpp-strings-length
title: "C++ String Length"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["length() function", "size() alias", "C++ 문자열 길이"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.83
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["cpp", "programming-language", "w3schools", "strings", "length"]
raw_sources: ["https://www.w3schools.com/cpp/cpp_strings_length.asp"]
applied_in: []
github_commit: ""
---

# [[CPP String Length]]

## 🎯 한 줄 통찰 (One-line insight)
`length()` and `size()` are explicitly stated to be EXACT ALIASES for each other — not two functions that happen to behave similarly, but literally the same operation under two names — meaning code encountered "in the wild" using `size()` instead of `length()` isn't using a different technique, just a different spelling of the identical call, and the choice between them is purely stylistic. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`.length()`** — returns the number of characters in a string. [S1]
- **`.size()`** — an exact ALIAS of `.length()`; both do precisely the same thing. [S1]
- **No functional difference** — unlike C's `sizeof` vs `strlen` distinction (which measure genuinely different things), C++'s `length()`/`size()` pair is purely a naming convenience with zero behavioral difference. [S1]

## 📖 세부 내용 (Details)
- Getting length via `.length()`: `string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; cout << txt.length(); // 26`. [S1]
- The identical result via `.size()`: `cout << txt.size(); // 26, same result`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **length()와 size()는 완전한 별칭**: C의 sizeof/strlen처럼 서로 다른 것을 측정하는 관계가 아니라, C++의 length()와 size()는 정확히 동일한 동작을 하는 두 개의 이름일 뿐이라는 점이 명시적으로 확인됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 다른 사람의 C++ 코드에서 size()를 볼 수도 있다는 점을 미리 알아두면 실전 코드 독해에 도움이 된다. [S1]

## 💻 코드 패턴 (Code patterns)
length() and size() are exact aliases of each other (C++):
```cpp
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << txt.length(); // 26
cout << txt.size();   // 26, identical result
```

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.83
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C++ Tutorial]]
- **관련 개념:** [[CPP Strings Input]], [[CPP Strings Namespace]], [[C Strings Functions]]
- **참조 맥락:** 문자열 길이 — 네임스페이스 생략(Strings Namespace) 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C++ String Length — https://www.w3schools.com/cpp/cpp_strings_length.asp

## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C++ String Length" page (Astra wiki-curation, P-Reinforce v3.1 format).
