各类型的数据操作 char string int long float等

   

char 与 int之间的转换    https://blog.youkuaiyun.com/smilesundream/article/details/77881995

cout 输出string https://www.cnblogs.com/mzct123/p/4876185.html

 C++字符串操作    https://www.cnblogs.com/lidabo/p/3487043.html

iomanip用法  https://blog.youkuaiyun.com/qq_37336280/article/details/81708527

#include <iostream>
#include<string>    //有此头文件可以cout输出字符串
#include<iomanip>	//有此头文件可以对cout操作加以限定(增加操作属性)
using namespace std;
 
int main ()
{

  { //常见数据类型,存储展示
   long   l = 11.22;    //整数型数据,在赋值过程中,转换为整型,舍弃小数点数据
   cout << l << endl;   //11

   float  f = 12.34567;  //float 小数点后4位数据
   cout << f << endl;   //12.3457

   double d = 30949.3574;
   cout << d << endl;   //30949.3
   }

  { //char型字符存储数字,
   short  s =90;
   cout << s << endl;   //90
   char   h = 90;  //数字可以直接赋值给 char变量,但是字符内容需经过指针
   cout << h << endl;   //Z  //ASCAll码的展示用char型
   }


   {//char型字符转换成数字方式,cout输出方式
	char   hh = 90;
	int aa = (int)hh;     //"字符数字"转化为int型数据 ,使用强制类型转换
	cout << aa <<endl;    //90  10进制形式
	cout <<setbase(16)<<setfill( '*' )<<setw(6)<<aa<<endl;  //****5a    //填充"*",显示16进制的数据90=5a
	}
   {
	char tt[] =  "+";
	cout << tt << endl;  //字符 用char展示,用数组形式
   }

   {// char 字符串与string 共同可以展示一串字符
	char s2[10] = "qwerty+=";  //字符串字符部分的定义,需要用指针/数组形式
    cout << s2 << endl;  //qwerty+=

    char* s1 = "hellow char--%%";  
    cout << s1 << endl; //hellow char--%%

    string str = "hellow string++**"; 
    cout << str << endl; //hellow string++**

	char bb = str.at(3);  //取出字符串中某一字符
	cout << bb << endl;   //l

	int cc = (int)bb;    //对字符进行数据转换  
	cout << cc << endl;  //6c   //16进制形式

   }
 system( "PAUSE "); 
   return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值