Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 코스닥
- java정리
- 모의 주식
- 코딩독학
- 개인프로젝트
- 프로그램
- 코딩테스트
- 프로그래밍
- 개발자
- Python
- 프로그래머스
- 자바정리
- 코딩
- 개발
- 이웃한 칸
- C++
- 풀스택프레임워크
- 주가예측
- 사물인터넷
- SNS
- 자바
- frontend
- 빅데이터
- backend
- 코테
- java
- 백준
- 자바독학
- Reflex
- Project
Archives
- Today
- Total
Creative Code
string4(const_cast) 본문
※main.cpp파일
#include <iostream>
#include "string.h"
int main() {
String s1;
String s2 = "hello, world"; // String s2("hello,world");
//String s2 = 0; // NULL
String s3 = s2; // String s3(s2);
s1 = s2;
String s4 = " IoT";
s1 = s2 + s4;
s1 = "hello, "; //String tmp("hello, ");
if (s1 == s2) std::cout << "s1 and s2 are equal" << std::endl;
else std::cout << "s1 and s2 are not equal" << std::endl;
s4+= s4;
s1 != s2;
std::cout << "s1 : " << s1.c_str() << std::endl;
std::cout << "s2 : " << s2.c_str() << std::endl;
std::cout << "s2 len : " << s2.size() << std::endl;
std::cout << "s3 : " << s3 <<std::endl;
const String s5 = "hello";
//s5 = "world";
std::cout << "s5 len : " << s5.size() << std::endl;
char *str = const_cast<char *>(s1.c_str()); // 상수성을 없앨 때 const_cast를 쓴다.
return 0;
}
'C++ Programming' 카테고리의 다른 글
complex6(inline함수, namespace) (1) | 2023.09.11 |
---|---|
shape(dynamic_cast) (0) | 2023.09.08 |
pointer3.cpp(reinterpret_cast) (0) | 2023.09.08 |
genderRatio.cpp(static_cast) (0) | 2023.09.08 |
safeArray4(try-throw-catch) (0) | 2023.09.08 |