在c++中函数empty()怎么使用,判断字符串是否为空,请问怎么判断??

如题所述

string s = "";if (s.empty())
{
cout <<
"字符串为空。。";
}
else
{
cout << "字符串不为空。。";
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-19
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()//主函数没有返回值
{
string s="1";
if(s.empty())
cout<<"为空"<<endl;
else
cout<<"非空"<<endl;
system("pause");//停留屏幕,便于观察结果
return 0;
}

//empty()是String类的方法,只能被调用
相似回答