---
id: cpp-strings-numbers
title: "C++ Numbers and Strings"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["+ operator overload", "string vs number addition", "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", "strings", "operator-overloading"]
raw_sources: ["https://www.w3schools.com/cpp/cpp_strings_numbers.asp"]
applied_in: []
github_commit: ""
---

# [[CPP Numbers and Strings]]

## 🎯 한 줄 통찰 (One-line insight)
`+` isn't ONE operator with one behavior — it's overloaded to mean completely different things depending on operand type: numeric `+` performs arithmetic addition (`"10" + "20"` as ints = `30`), while string `+` performs concatenation (`"10" + "20"` as strings = `"1020"`), and mixing the two (a string plus a number) is explicitly flagged as an ERROR — meaning `+`'s meaning is entirely determined by the DECLARED TYPES of its operands, with no automatic conversion bridging string and number. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`+` on numbers** — performs arithmetic addition: `int x = 10; int y = 20; int z = x + y; // 30`. [S1]
- **`+` on strings** — performs concatenation, NOT addition: `string x = "10"; string y = "20"; string z = x + y; // "1020"`. [S1]
- **Mixing string and number with `+` fails** — `string x = "10"; int y = 20; string z = x + y;` produces an error; there's no automatic string-to-number or number-to-string coercion for `+`. [S1]

## 📖 세부 내용 (Details)
- Numeric addition: `int x = 10; int y = 20; int z = x + y; // z will be 30 (an integer)`. [S1]
- String concatenation with the SAME `+` symbol producing a totally different result: `string x = "10"; string y = "20"; string z = x + y; // z will be 1020 (a string)`. [S1]
- The explicit error case: `string x = "10"; int y = 20; string z = x + y; // error`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **+ 연산자는 피연산자 타입에 따라 완전히 다른 동작**: 숫자끼리는 산술 덧셈, 문자열끼리는 연결(concatenation)을 수행하며, 문자열과 숫자를 섞어서 더하면 에러가 발생한다는 점이 "WARNING!"으로 강조되어 명시됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 사용자 입력이 숫자처럼 보여도 실제로는 문자열(string) 타입일 수 있어, + 연산 시 의도치 않게 덧셈 대신 연결이 일어날 수 있다는 점을 실전에서 주의해야 한다. [S1]

## 💻 코드 패턴 (Code patterns)
The + operator meaning completely different things for numbers vs. strings (C++):
```cpp
int x = 10;
int y = 20;
int z = x + y;      // z will be 30 (an integer)

string a = "10";
string b = "20";
string z2 = a + b;  // z2 will be "1020" (a string)
```

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

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C++ Tutorial]]
- **관련 개념:** [[CPP Strings Namespace]], [[CPP Math]], [[CPP Operators Arithmetic]]
- **참조 맥락:** 문자열 섹션 마지막 — 수학 함수(Math) 섹션으로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C++ Numbers and Strings — https://www.w3schools.com/cpp/cpp_strings_numbers.asp

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