본문 바로가기
Computer Languages/C | C++

string::getline

by blackcon 2010. 11. 19.
728x90
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

728x90