6.29-每日面试题

6.29-每日面试题

1、什么是快表,快表作用
在这里插入图片描述

2、分页存储为什么每页大小是4K
在这里插入图片描述
3、字符串和数值的转换如何实现
C++中字符串与数值转换(超详细)

1、使用stringstream
1)、stringstream

#include<iostream>
#include<sstream>
using namespace std;

int main(){
	int i = 1;
	float f = 1.2;
	double d = 1.23;
	//数值->字符串
	stringstream ss1;
	ss1 << i << " " << f << " " << d << endl;
	string result = ss1.str();
	cout << "result = " << result;
	//字符串->数值
	string str = "123.5";
	//stringstream ss2(str);
	stringstream ss2;
	ss2 << str;
	ss2 >> i >> f;
	cout << "i = " << i << "\nf = " << f << endl;
	system("pause");
	return 0;
}

2)、istringstream和ostringstream(这块我不太懂,是想说明写的方式不同吗,但是可以实现相同的功能?)

#include<iostream>
#include<sstream>
using namespace std;

int main(){
	int i = 1;
	float f = 1.2;
	double d = 1.23;
	
    //数值->字符串
	ostringstream oss;
	oss << i << " " << f << " " << d << endl;//输出流
	string result = oss.str();
	cout << "result = " << result;

	//字符串->数值
	string str = "123.5";
	istringstream iss(str);
	iss >> i >> f; //输入流
	cout << "i = " << i << "\nf = "<<f << endl;

	system("pause");
	return 0;
}

2、使用函数
字符串转换成数值: stoi()等等
在这里插入图片描述

#include <iostream>
#include<string>
using namespace std;
int main()
{
	string str = "123.345";
	int i = stoi(str);
	float f = stof(str);
	double d = stod(str);
	cout << "i = " << i << "\nf = " << f <<"\nd = "<<d<< endl;

	system("pause");
	return 0;
}

3、char数组转换成数值
在这里插入图片描述
4、数值转换成字符串
#include头文件中:inline string to_string(val);
举例:string to_string (int val);

#include <iostream>
#include<sstream>
using namespace std;
int main()
{
	int i = 1;
	float f = 1.2;
	double d = 1.23;
	
	cout<< to_string(i) << " " << to_string(f) << " " << to_string(d) << endl;// 1 1.200000 1.230000
	system("pause");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值