`
happmaoo
  • 浏览: 4341976 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

学会从已知推出未知

阅读更多

本人是一个英语菜鸟。因为英语是计算机的官方语言。因此学起计算机自然有了麻烦。具体的表现是看msdn常常对自己的理解感到不自信:我的理解到底对不对呢?幸好我想到了一个好办法,就通过已知的知识来推测未知的。比如我STL中的string中的成员函数erase函数的功能:

basic_string& erase(size_type p0 = 0, size_type n = npos);

function removes up to n elements of the controlled sequence beginning at position p0, then returns *this.

我不知道remove up 作何解。我通过查金山词霸,知道remove有移动、开除、移交的意思。我猜这个函数有清空字符串的功能。但是我依然不能肯定。于是我设计了一个小实验来验证我的想法。

#include <stdio.h>
#include <conio.h>
#include <string>
using namespace std;

int main(void)
{
string str;
str = "Hello";
str.erase();

/*之前我已经知道str.empty()是判断字符串是否为空,空则返回true。*/
if(str.empty())printf("str is empty!\n");
return 0;
}

果然不出我的所料。erase函数的功能就是清空字符串。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics