C++原型(Win32和Linux):
#include <iostream>
istream& getline ( istream &is , string &str , char delim );
istream& getline ( istream& , string& );
說明:
在終結符的處理上(默認換行符作爲終結符)
在遇到終結符delim後,delim會被丟棄,不存入str中。在下次讀入操作時,將在delim的下個字符開始讀入
測試代碼:
#include <iostream>
#include <string>
int read_line(void)
{
std::string buf;
getline(std::cin, buf);
std::cout << buf;
return 0;
}
C原型(Linux):
#include <stdio.h>
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
測試代碼:
#include <stdio.h>
int read_line_c(void)
{
char buffer[100];
getline(buffer, sizeof(buffer), stdin);
printf(buffer);
}
說明:
DESCRIPTION
getline() reads an entire line from stream, storing the address of the
buffer containing the text into *lineptr. The buffer is null-terminated and includes the newline character, if one was found.
用於讀取一行字符直到換行符,包括換行符
備註:
相關的函數,對於fgets()函數,兩個平臺下都會讀取換行符,gets()函數,兩個平臺下都不會讀取換行符
http://baike.baidu.com/view/3127321.htm
http://baike.baidu.com/view/8684247.htm