Search

문자 ↔ 숫자

νƒœκ·Έ

char β†’ int

μ•„μŠ€ν‚€ μ½”λ“œ ν™œμš© ( β€˜0’ 을 λΉΌμ€€λ‹€ )
ex) char β€˜3’ β†’ int 3 으둜 λ³€ν™˜
β€˜3’ - β€˜0’ : 3

int β†’ char

β€˜0’ 을 더해주면 λœλ‹€
#include <bits/stdc++.h> using namespace std; int main() { int a = 3; cout << (char)(a + '0'); // '3' }
C++
볡사

int β†’ string

β€’
to_string() μ‚¬μš©
β€’
int 뿐만 μ•„λ‹ˆλΌ λͺ¨λ“  숫자 νƒ€μž…μ— μ‚¬μš©κ°€λŠ₯ν•˜λ‹€.
#include <bits/stdc++.h> using namespace std; int main() { int a = 123456; cout << to_string(a); // "123456" }
C++
볡사

string β†’ int

β€’
stoi (string to int)
β€’
cf
β—¦
stof : string to float
β—¦
stol : string to long
β—¦
stod : string to double
#include <bits/stdc++.h> using namespace std; int main() { string s = "100"; int i = stoi(s); // string -> int cout << i; // 100 }
C++
볡사