回 帖 发 新 帖 刷新版面

主题:疑惑!!!!

请教各位 get 和 getline 的具体用法 和区别

回复列表 (共1个回复)

沙发

Gets a line from the input stream.

 
basic_istream& getline(
   char_type *_Str, 
   streamsize _Count
);
basic_istream& getline(
   char_type *_Str, 
   streamsize _Count, 
   char_type _Delim
);
 


Parameters
_Count
The number of characters to read from strbuf.

_Delim
The character that should terminate the read if it is encountered before _Count.

_Str
A string in which to write.

Return Value
The stream (*this).

// 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
 

我来回复

您尚未登录,请登录后再回复。点此登录或注册