Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
c:라이브러리_추가가_필요한_자료형 [2022/01/17 15:09] – jonghoon | c:라이브러리_추가가_필요한_자료형 [2022/01/19 14:08] – jonghoon | ||
---|---|---|---|
Line 23: | Line 23: | ||
| ::: | ::: | stod(" | | ::: | ::: | stod(" | ||
| string.substr(start, | | string.substr(start, | ||
- | | string.c_str() | string 자료형인 문자열을 const char 형 배열로 변환하여 반환한다. | " | + | | string.c_str() | string 자료형인 문자열을 const char형 |
substr의 경우 인자가 하나만 있으면 start위치부터 끝까지를 반환한다. | substr의 경우 인자가 하나만 있으면 start위치부터 끝까지를 반환한다. | ||
Line 29: | Line 29: | ||
다음은 각 함수를 사용하는 코드다. | 다음은 각 함수를 사용하는 코드다. | ||
- | <Code:C++> | + | <code:C++ | example_string.cpp> |
#include < | #include < | ||
#include < | #include < | ||
Line 54: | Line 54: | ||
string sub1 = str1.substr(5);// | string sub1 = str1.substr(5);// | ||
string sub2 = str1.substr(5, | string sub2 = str1.substr(5, | ||
+ | string sub3 = sub1 + sub2;// sub3 = " | ||
| | ||
const char *ch = str1.c_str(); | const char *ch = str1.c_str(); | ||
Line 62: | Line 63: | ||
cout << " | cout << " | ||
cout << " | cout << " | ||
+ | cout << " | ||
cout << "str to char array: " << ch << "\t type: " << typeid(ch).name() << " | cout << "str to char array: " << ch << "\t type: " << typeid(ch).name() << " | ||
} | } | ||
- | </Code> | + | </code> |
+ | |||
+ | 실행결과는 다음과 같다. | ||
+ | |||
+ | str: 1234.56789 $\quad$ type: std::_ _cxx11:: | ||
+ | str to int: 1234 $\quad$ type: int\\ | ||
+ | str to double: 1234.56789 $\quad$ type: double\\ | ||
+ | substr one parameter: 56789 $\quad$ type: std::_ _cxx11:: | ||
+ | substr two parameter: 567 $\quad$ type: std::_ _cxx11:: | ||
+ | string + operation: 56789789 $\quad$ type: std::_ _cxx11:: | ||
+ | str to char array: 1234.56789 $\quad$ type: char const*\\ | ||
+ | |||
+ | g++의 경우 typeid를 나름대로 define하여 쓰고 있어 그냥 실행하면 int는 i로 double은 d로 const char* 는 PKc로 나타난다. | ||
+ | 위와 같이 정확한 명칭으로 나타나게 하기 위해서는 | ||
+ | < | ||
+ | ./ | ||
+ | </ | ||
+ | 형식으로 실행을 해야한다. | ||
+ | |||
+ | ===== vector ===== |