33,311
社区成员
发帖
与我相关
我的任务
分享
// 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;;
}
basic_istream& getline(
char_type *_Str,
streamsize _Count
);
basic_istream& getline(
char_type *_Str,
streamsize _Count,
char_type _Delim
);
// basic_istream_getline.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
int main( )
{
char c[10];
cin.getline( &c[0], 5, '2' );
cout << c << endl;
}
Input
12
Output
1