3.3.9 使用empty()成员函数
empty()成员函数返回bool型值,如果string对象为空,则返回true,否则返回false。下面的代码使用了empty():
因为phrase等于空字符串,所以phrase.empty()返回true,且屏幕显示消息"The phrase is no more."
- if (phrase.empty())
- {
- cout << "\nThe phrase is no more.\n";
- }
3.3.9 使用empty()成员函数
empty()成员函数返回bool型值,如果string对象为空,则返回true,否则返回false。下面的代码使用了empty():
因为phrase等于空字符串,所以phrase.empty()返回true,且屏幕显示消息"The phrase is no more."
- if (phrase.empty())
- {
- cout << "\nThe phrase is no more.\n";
- }