三件套:char>int int>char bool>int
主要就是:
(节选)
1
int main()
{
//批注:这是 char 转 int 的代码。不要搞混了
char ch;
cin>>ch//我用#iostream
cout<}
2
int main()
{
//批注:这是 int 转 char
int in;
cin>>in;
cout<}
3
int main()
{
//批注:bool 变 int
main3:
char bo;
bool Bo;
cout<<"t/f, "<cin>>bo;
if(bo==116)
{
Bo=true;
cout<Bo=false;
goto main3;
}
else if(bo==102)
{
Bo=false;
cout<Bo=false;
goto main3;
}
}
全代码:
#include
using namespace std;
int main()
{
M:
cout<<"\nwhich kind of trans? 1 ch>in; 0 in>ch; 2 bo>in; 3 to exit"<int choose;
cin>>choose;
if(choose==1)
{
cout<<"0 go back"<main:
char ch;
cin>>ch;
if(ch==48)
{
goto M;
}
cout<goto main;
}
else if(choose==0)
{
cout<<"0 go back"<main2:
int in;
cin>>in;
if(in==0)
{
goto M;
}
cout<goto main2;
}
else if(choose==2)
{
main3:
char bo;
bool Bo;
cout<<"t/f, b to go back"<cin>>bo;
if(bo==116)
{
Bo=true;
cout<Bo=false;
goto main3;
}
else if(bo==102)
{
Bo=false;
cout<Bo=false;
goto main3;
}
else if(bo=98)
{
goto M;
}
else
{
cout<<"error!"<goto main3;
}
}
else if(choose==3)
{
return 0;
}
else
{
cout<<"error!"<<" ";
goto M;
}
}
int main()
{
int m=65;
cout<<(char)m;
return 0;
}
强制转换成char
比如int a=65,它对应的字符为A,那么这样输出就能够输出65对应的字符A:
cout<<(char)a<
main()
{
for(int i =1;i<128;i++)
{
cout< }
}
输出1到127所对应的ascii码字符。
cout<<\xxx
cout<<(char)72