Notice
Recent Posts
Recent Comments
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 |