知识库
前天学习了,但没更新博客,持续每天一更
1.while(vector<int>::iterator iter!=ivec.end())
{/*·······*/}
这段程序有什么问题???
2.string bufString,word;
while(cin>>bufString>>word){/*······*/}
怎样更正输入方式???
3. 算术转换的基本知识
char cval; unsigned int uival; short sval; long lval;
unsigned short usval; unsigned long ulval; float fval; double dval;
3.14159L+'a';//promote 'a' to int,then convert to long double
cval+fval;//cval promoted to int,that int convertd to float
sval+cval;//sval and cval promoted to int
cval+lval;//cval converted to long
usval+ival;//promotion depends on size of unsigned short and int
uival+lval;//convertion depends on size of unsigned int and long
4. 命名的强制类型转换
符号的一般格式如下:
cast-name<type>(expression);
其中cast-name为static_cast、dynamic_cast、const_cast、和reinterpret_cast之一,type为转换的目标类型,而expression则是被强制转换的值。
/*建议:避免使用强制类型转换*/
5.switch内部的变量定义
对于switch结构,只能在他的最后一个case标号或default标号后面定义变量:
case true:
//error:declaration precedes a case lable
string file_name=get_file_name();
break;
case false:
//```
注意:如果需要为某个特殊的case定义变量,则可以引入块语句,在该块语句中定义变量,从而保证这个变量在使用之前被定义和初始化。
case true:
{
//ok:declaration statement within a statement block
string file_name();
//······
}
break;
case false:
//······