The C++ empty() member function program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using the C++ empty() member function to test whether the string is contains characters or not
To show: How to use the C++ empty() member function to to test whether the string is contains characters or not.
// the C++ empty() program example
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
bool Var1, Var2;
string str1("Testing the empty()");
cout<<"str1 string object is: "<<str1<<endl;
Var1 = str1.empty();
// test the emptiness
cout<<"Operation: str1.empty()"<<endl;
if(Var1)
cout<<"str1 string object is empty."<<endl;
else
cout<<"str1 string object is not empty."<<"\n\n";
// an example of an empty string object
string str3;
Var2 = str3.empty();
cout<<"Operation: str3.empty()"<<endl;
// test the emptiness
if(Var2)
cout<<"str3 string object is empty."<<endl;
else
cout<<"str3 string object is not empty."<<endl;
return 0;
}
Output example:
str1 string object is: Testing the empty()
Operation: str1.empty()
str1 string object is not empty.
Operation: str3.empty()
str3 string object is empty.
Press any key to continue . . .