๐ฑ ๊ธธ์ด์ธก์ ๋ฐ ๋ฌธ์์ด ๋น์ฐ๊ธฐ
size : ๋ฌธ์์ด์ ๊ธธ์ด ๋ฐํ.
length : ๋ฌธ์์ด์ ๊ธธ์ด ๋ฐํ.
maxsize : ๊ฐ๋ฅํ ์ต๋ ๋ฌธ์์ด ๊ธธ์ด๋ฅผ ๋ฐํ.
clear : ๋ฌธ์์ด ๋น์ฐ๊ธฐ.
empty : ๋ฌธ์์ด ๋น์์ง ์ฌ๋ถ ํ์ธ.
๐ฑ ์ฝ๋์์ฑ
#include <iostream>
#include <string>
int main(void)
{
// ์ ์ธ
std::string str;
// ์ด๊ธฐํ
str = "junselee";
// ์ด๊ธฐํํ ๋ฌธ์ ์ด์ ๊ธธ์ด ์ถ๋ ฅ
std::cout << "size : " << str.size() << std::endl;
// ์ด๊ธฐํํ ๋ฌธ์์ด์ ๊ธธ์ด ์ถ๋ ฅ
std::cout << "length : " << str.length() << std::endl;
// ๊ฐ๋ฅํ ์ต๋๋ฌธ์์ด์ ํฌ๊ธฐ ์ถ๋ ฅ
std::cout << "max_size : " << str.max_size() << std::endl;
// ๋ฌธ์์ด ๋น์ฐ๊ธฐ
str.clear();
std::cout << "clear : " << str << std::endl;
// ๋ฌธ์์ด์ด ๋น์ด์๋์ง ์ถ๋ ฅ (1 : ๋น์ด์์, 0 : ๋น์ด์์ง์์)
std::cout << "empty : " << str.empty() << std::endl;//๋น์ด์์ผ๋ฉด 1 ์๋๋ฉด 0
return 0;
}
๐ฑ ์คํ๊ฒฐ๊ณผ
junselee /cpp_contents clang++ test.cpp -o test #์ปดํ์ผ
junselee /cpp_contents ./test #์คํ
size : 8 #๋ฌธ์์ด "junselee"์ ๊ธธ์ด
length : 8 #๋ฌธ์์ด "junselee"์ ๊ธธ์ด
max_size : 18446744073709551599 #๊ฐ๋ฅํ ๋ฌธ์์ด์ ์ต๋๊ธธ์ด
clear : #๋ฉค๋ฒํจ์ clearํธ์ถ ํ ๋ฌธ์์ด์ถ๋ ฅํ์ธ
empty : 1 #๋น์์ง ์ฌ๋ถ ํ์ธ (1 : ๋น์์ง)
'๊ฐ๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[vscode] ํฐ๋ฏธ๋ ์์น๋ณ๊ฒฝ (0) | 2021.11.21 |
---|---|
[Mac] ์ํ๋ ๋(Alfred) (0) | 2021.08.03 |
[C์ธ์ด] readline ํจ์ (1) | 2021.07.29 |