大兴区湿地公园路线:c++中getline 的用法

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 23:35:53
能举例说明getline的用法吗?
还有是不是可以用getline来表示输入任意键继续这个意思?
请问怎么输入??

The getline Function
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;
}

相对cin来说,cin.getline是读入一个包含空格在内的字符,常常用作程序暂停,等待输入。
具体用法可参照cin.