첫번째 문자열 예제를 코딩해 보자.
char? int? float?
#include <stdio.h>
int main() {
★ str = "Hello, David !!"; // string
printf("%s\\n", str);
return 0;
}
둘중의 하나가 오면 된다.
2개는 차이가 있는데, 이는 다음시간에 알아보자.
C++에는 string이라는 문자열 형이 있다.
걍 데이터형 이름이 string 형 이다.
그래서 아래와 같이 코딩 하면 된다.
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, David !!";
std::cout << str<<std::endl;
return 0;
}
c언어에서는 문자열을 저장하는 자료형이 없다.
char이 여러개니까 char[]로 저장하면 될것이다.
배열이란? = 같은 데이터형의 집합
int가 여러개 = int[]
char이 여러개 = char[]
#include <stdio.h>
int main() {
char str[] = "Hello, David !!";
printf("%s\\n", str);
return 0;
}