MemoryGarden's Blog

努力 -----------大能猫

C++博客 首页 新随笔 联系 聚合 管理
  118 Posts :: 11 Stories :: 20 Comments :: 0 Trackbacks
The string content is set to an empty string, erasing any previous content and thus leaving its size at 0 characters.

 1 // string::clear
 2 #include <iostream>
 3 #include <string>
 4 using namespace std;
 5 
 6 int main ()
 7 {
 8   string str;
 9   char c;
10   cout << "Please type some lines of text. Enter a period to finish:\n";
11   do {
12     c=cin.get();
13     str += c;
14     if (c=='\n')
15     {
16        cout << str;
17        str.clear();
18     }
19   } while (c!='.');
20   return 0;
21 }

posted on 2009-12-30 01:54 memorygarden 阅读(625) 评论(0)  编辑 收藏 引用 所属分类: STL

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理