Empty函式,此成员函式用来使CString对象成为一个空字元串,并释放相应的记忆体。
CString::Empty
void Empty( );
说明:
更多的信息,参见“Visual C++程式设计师指南”中的“字元串:CString异常清除”。
示例:下面的例子说明了如何使用CString::Empty。
// example for CString::Empty
CString s( "abc" );
s.Empty();
ASSERT( s.GetLength( ) == 0 );
请参阅 CString::IsEmpty
std::string::empty
BOOL empty();
函式功能:
测试string是否为空,返回此string对象是否为空,(即string对象的长度是否为0)。
函式说明:
此函式不会修改string对象。若要清空string对象的内容,见string::clear。
返回值:
如果string长度为0,则返回true,反之则返回false。
例:
// string::empty
#include <iostream>
#include <string>
int main ()
{
std::string content;
std::string line;
std::cout << "Please introduce a text. Enter an empty line to finish:\n";
do {
getline(std::cin,line);
content += line + '\n';
} while (!line.empty());
std::cout << "The text you introduced was:\n" << content;
return 0;
}
此程式功能是一行一行读取用户输入并存入content变数,直到输入一个空行为止。
以下的情况被认为是空的:
- ""(空字元串)
- 0(作为整数的0)
- 0.0(作为浮点数的0)
- "0"(作为字元串的0)
- NULL
- FALSE
- array()(一个空数组)
- $var;(一个声明了,但是没有值的变数)