728x90
728x170
*[STL] getline()
- C++에서 배열에 공백을 포함한 문장을 입력 받기 위해 필요한 함수. (C의 gets() 함수와 동일한 기능을 가지고 있음.)
- C++11 이후, gets() 함수가 C++의 표준 라이브러리에서 제외 되었기 때문에, 공백을 포함한 문장을 입력 받기 위해서는 이 함수가 필요함.
- 템플릿
(1) |
istream& getline (istream& is, string& str, char delim); istream& getline (istream&& is, string& str, char delim); |
(2) |
istream& getline (istream& is, string& str); istream& getline (istream&& is, string& str); |
- 자세한 내용 : http://www.cplusplus.com/reference/string/string/getline/?kw=getline
[예제 코드]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
#include <iostream>
#define N 100
using namespace std;
int main()
{
char ary[N];
cin.getline(ary, N);
for (int i = 0; i < strlen(ary); i++) {
cout << ary[i];
}
cout << endl;
} |
cs |
[출력 결과]
Hello World! Hello World! |
728x90
그리드형(광고전용)
'Programming > C++' 카테고리의 다른 글
[header][container] vector (0) | 2017.11.08 |
---|---|
[STL] binary_search (0) | 2017.11.08 |
[STL] bitset (0) | 2017.10.26 |
[STL] sprintf (0) | 2017.10.21 |
[STL] ceil, floor, round (0) | 2017.09.23 |
[STL] sort (0) | 2017.09.22 |
C++ Character Literals (0) | 2017.09.02 |
인수와 레퍼런스 (0) | 2017.05.30 |