Search

λ¬Έμžμ—΄(string) ↔ 문자(char)

νƒœκ·Έ

string β†’ char

#include <bits/stdc++.h> using namespace std; int main() { char ch[100]; string a = "hello world"; // c_str() 둜 string -> char* λ³€ν™˜ ν›„ // strcpy 둜 char 배열에 μ €μž₯ strcpy(ch, a.c_str()); cout << ch << '\n'; }
C++
볡사
β€’
c_str() κ³Ό strcpy() λ₯Ό 이용

char β†’ string

#include <bits/stdc++.h> using namespace std; int main() { char ch[100] = "hello world"; // string μƒμ„±μžλ₯Ό μ΄μš©ν•΄μ„œ char* -> string λ³€ν™˜ string new_str(ch); cout << new_str; }
C++
볡사
β€’
string μƒμ„±μž μ‚¬μš©
string λ³€μˆ˜λͺ…(char *)