string.empty(C String empty()实例讲解)
一、用c语言做判断题时if statement has empty body怎么解决
当有多个分支选择时,可采用if-else-if语句,其一般形式为:
if(表达式1)
语句1;
else if(表达式2)
语句2;
else if(表达式3)
语句3;
…
else if(表达式m)
语句m;
else
语句n;
其语义是:依次判断表达式的值,当出现某个值为真时,则执行其对应的语句。然后跳到整个if语句之外继续执行程序。如果所有的表达式均为假,则执行语句n。然后继续执行后续程序。 if-else-if语句的执行过程如下图所示。
参考代码如下:
char c;
printf("input a character:");
c=getchar();
if(c<32)
printf("This is a control character\n");
else if(c>='0'&&c<='9')
printf("This is a digit\n");
else if(c>='A'&&c<='Z')
printf("This is a capital letter\n");
else if(c>='a'&&c<='z')
printf("This is a small letter\n");
else
printf("This is an other character\n");
return 0;
本例要求判别键盘输入字符的类别。可以根据输入字符的ASCII码来判别类型。由ASCII码表可知ASCII值小于32的为控制字符。在“0”和“9”之间的为数字,在“A”和“Z”之间为大写字母,在“a”和“z”之间为小写字母,其余则为其它字符。
这是一个多分支选择的问题,用if-else-if语句编程,判断输入字符ASCII码所在的范围,分别给出不同的输出。例如输入为“g”,输出显示它为小写字符。
扩展资料:
在使用if语句中还应注意以下问题:
1、在if关键字之后均为表达式。该表达式通常是逻辑表达式或关系表达式,但也可以是其它表达式,如赋值表达式等,甚至也可以是一个变量。例如:
if(a=5)语句;
if(b)语句;
都是允许的。只要表达式的值为非0,即为“真”。如在:
if(a=5)…;
中表达式的值永远为非0,所以其后的语句总是要执行的,当然这种情况在程序中不一定会出现,但在语法上是合法的。
2、在if语句中,条件判断表达式必须用括号括起来,在语句之后必须加分号。
3、在if语句中,所有的语句应为单个语句,如果要想在满足条件时执行一组(多个)语句,则必须把这一组语句用{}括起来组成一个复合语句。但要注意的是在}之后不能再加分号。
参考资料:
Microsoft-if-else(C#参考)
菜鸟教程-C#if语句
二、error C2228: ".empty"的左边必须有类/结构/联合
修改了一下
h文件
#if!definedSTACK_2_T_H
#defineSTACK_2_T_H
enum{EXIT_SUCCESS,UNDERFLOW,OVERFLOW};//这一系列errcode没定义我随便写了
constintmaxstack=10;
//typedefcharStack_entry;//数组
typedefintError_code;
template<classStack_entry>
classStack{
public:
Stack();
boolempty()const;
Error_codepop();
Error_codepush(constStack_entry&item);
Error_codetop(Stack_entry&item)const;
private:
intcount;
Stack_entryentry[maxstack];
};
#endif
源文件改动比较大你自己对一下
#include<iostream>
usingnamespacestd;
template<classStack_entry>
Stack<Stack_entry>::Stack(){
count=0;
}
template<classStack_entry>
Error_codeStack<Stack_entry>::push(constStack_entry&item){
Error_codeoutcome=EXIT_SUCCESS;
cout<<"push操作已被重写"<<endl;
if(count>=maxstack)
outcome=OVERFLOW;
else
entry[count++]=item;
returnoutcome;
}
template<classStack_entry>
Error_codeStack<Stack_entry>::pop()
{
Error_codeoutcome=EXIT_SUCCESS;
if(count==0)
outcome=UNDERFLOW;
else
--count;
returnoutcome;
}
template<classStack_entry>
Error_codeStack<Stack_entry>::top(Stack_entry&item)const{
Error_codeoutcome=EXIT_SUCCESS;
if(count==0)
outcome=UNDERFLOW;
else
item=entry[count-1];
returnoutcome;
}
template<classStack_entry>
boolStack<Stack_entry>::empty()const{
booloutcome=true;
if(count>0)
outcome=false;
returnoutcome;
}
intmain()
/*pre:theusersuppliesanintegernandndecimalnumbers.
post:thenumbersarepeintedinreverseoeder.
users:thestlclassstackanditsmethods*/
{
intm;
doubleitem;
Stack<double>numbers;
cout<<"Typeinanintegernfollowedbyndecimalnumbers"<<endl
<<"thenumberswillbeprintedinreverseorder"<<endl;
cin>>m;
for(inti=0;i<m;i++){
cin>>item;
numbers.push(item);
}
cout<<endl<<endl;
while(!numbers.empty()){
numbers.top(item);
cout<<item<<"";
numbers.pop();
}
cout<<endl;
}
其实错误很简单就是你定义的stack是类的形式但是调用的时候用的是模板的形式
所以改成类模板的写法就可以了
另外你定义的pop用法和你使用的方式不同一并改了
三、...应用哪个英语单词A、bare B、empty C、blank D、vacant
1、empty wall只表示墙上没挂东西
例如:The television was facing an empty wall.
这台电视面对着一堵空墙。
2、blank wall主要表示毫无进展的状态,无法克服的障碍;有时候可以表示没有门窗的墙和没挂东西的墙;
如短语:run into a blank wall的意思是碰壁
例如:Attempts to get further information by questioning the
captives ran into a blank wall.
审讯俘虏以获得更多情报的试图未能取得任何进展。
现在知道应该用empty wall了吧!