반응형
string의 getline함수는 cin으로 입력받을때 공백도 같이 입력받을수 있다.
[예제]
[예제]
// string_getline_sample.cpp
// compile with: /EHsc
// Illustrates how to use the getline function to read a
// line of text from the keyboard.
//
// Functions:
//
// getline Returns a string from the input stream.
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
using namespace std ;
int main()
{
string s1;
cout << "Enter a sentence (use <space> as the delimiter): ";
getline(cin,s1, ' ');
cout << "You entered: " << s1 << endl;;
}
출처 : www.msdn.com
'Computer Languages > C | C++' 카테고리의 다른 글
| Winpcap Developer 초기 설정 (0) | 2015.07.16 |
|---|---|
| [인공지능] A* 알고리즘을 이용한 8-puzzle 만들기 (10) | 2015.04.04 |
| string을 char로 취급하기 (0) | 2010.10.21 |
| [펌]private, proteted, public 의 차이 (3) | 2010.10.12 |
| [펌] new와 delete (0) | 2010.10.11 |