注册 登录
编程论坛 C++教室

本菜鸟一直对getline 有点不懂

asd6791868 发布于 2008-12-13 14:43, 1173 次点击
哪位达人能举一个简单而且易懂的例子给我!~


谢谢拉
5 回复
#2
PcrazyC2008-12-14 15:17
MSDN

The getline member function is similar to the get function. Both functions allow a third argument that specifies the terminating character for input. The default value is the newline character. Both functions reserve one character for the required terminating character. However, get leaves the terminating character in the stream and getline removes the terminating character.

The following example specifies a terminating character for the input stream:

#include <iostream.h>

void main()
{
   char line[100];
   cout << " Type a line terminated by 't'" << endl;
   cin.getline( line, 100, 't' );
   cout << line;
}
#3
PcrazyC2008-12-14 15:19
输入一行字符,以T结尾

比如输入2342DFEFTEFEFEF

LINE的结果就是前面的2342DFEF,遇到T就结束
#4
asd67918682008-12-14 16:03
了解  
谢谢了
1