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

这是个什么格式个getline(cin,s[i])

げ訾澐み 发布于 2007-07-20 16:37, 1704 次点击
getline(cin,s[i])是什么意思
他和cin.getlines([i])一样吗
还有顺便帮我解释下cin.getlines()我只知道他是输入一个字符串,就我的理解是输入字符串遇到“\n"的时候就停止对吗 ?
3 回复
#2
maoguoqing2007-07-20 22:12
getline(cin,s[i]);就是读入一个字符串保存在s[i]中,s[i]肯定是string类型的
cin.getlines([i]);是cin.getline,而且没有你这种表达形式,自己看看msdn,默认情况下遇到'\n'
停止,但是你可以通过第三个参数进行设置。。
#3
一番宝瓶2007-07-20 22:27
多看看msdn

getline(cin,s[i]);
-------------------------------------------------------------------
Syntax:
  istream& getline( istream& is, string& s, char delimiter = '\n' );

The C++ string class defines the global function getline() to read strings from and I/O stream. The getline() function, which is not part of the string class, reads a line from is and stores it into s. If a character delimiter is specified, then getline() will use delimiter to decide when to stop reading data.

For example, the following code reads a line of text from STDIN and displays it to STDOUT:

 string s;
 getline( cin, s );
 cout << "You entered " << s << endl;
-----------------------------------------------------------------
cin.getline(str[i]);
-----------------------------------------------------------------

Syntax:
  istream& getline( char* buffer, streamsize num );
  istream& getline( char* buffer, streamsize num, char delim );

The getline() function is used with input streams, and reads characters into buffer until either:

  • num - 1 characters have been read,
  • a newline is encountered,
  • an EOF is encountered,
  • or, optionally, until the character delim is read. The delim character is not put into buffer.
    ------------------------------------------------------------


#4
野比2007-07-21 00:18

现在看msdn都没时间了... 完全靠臆断...

1