荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: kaman (天外飛仙), 信区: Program
标  题: Re: 讨论:getline()的用法...
发信站: 荔园晨风BBS站 (2005年12月25日16:06:36 星期天), 站内信件


我记得getline不读的,

vc6对标准支持不太好,microsoft曾经承认过这个bug的:

FIX: getline Template Function Reads Extra Character
RESOLUTION
Modify the getline member function, which can be found in the following system
header file "string", as follows:
 else if (_Tr::eq((_E)_C, _D))
       {_Chg = true;
    //  _I.rdbuf()->snextc();   // Remove this line and add the line below.
        _I.rdbuf()->sbumpc();
         break; }
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
This problem was corrected in Microsoft Visual C++ .NET.
MORE INFORMATION
The following sample program demonstrates the bug: //test.cpp
#include <string>
#include <iostream>
int main () {
std::string s,s2;
std::getline(std::cin,s);
std::getline(std::cin,s2);
std::cout << s <<'\t'<< s2 << std::endl;
return 0;
}
//Actual Results:
Hello<Enter Key>
World<Enter Key>
<Enter Key>
Hello   World
//Expected Results:
Hello<Enter Key>
World<Enter Key>
Hello   World
--------------------------------------------------------------------------------
APPLIES TO
? The Standard C++ Library, when used with:
  Microsoft Visual C++ 6.0 Enterprise Edition
  Microsoft Visual C++ 6.0 Professional Edition
  Microsoft Visual C++ 6.0 Standard Edition


【 在 starsun (小刚与微软 ) 的大作中提到: 】
: cin.getline(char *, int, char),读取由int字段指定长度的字符串,或读到char字段所

:
: 定的字符为止。
: 注意的是:getline()如果在遇到回车符也会结束的,不过它和get()不同的是它会把回车符

:
: 读进字符串中!
:
:
: 我记得我学的是这样的,不知各们同学有什么不同的意见.


--
           ╃  ╮  ┽·/   ┞ーゝ  ╱丿┒   /│·  丿 /┒   ─┒   ーフ
  ━─   ─┾ ㄈ   ┽╅+     ┞    │.┃    ╅┾    |つ.┃  │-┃  ━╁
          ┢˙─   ┙╯|   ━-フ   ┃ ノ°  ╃ ヤ   レ` ┚   ─┚    ╯

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.2.122]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店