(1)、find()函数
string name="dddfsfs";
int index = name.find('d'); //返回d第一次出现时的下标
(2)、insert函数
a = str.insert(4,"sky");
//在下标为4的位置,插入字符串sky
b = str.insert(4,5,'x');
//在下标为4的位置,插入字符串5个字符x
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, f1, num1, num2, f2, num3, res = "";
cin >> str;
int nDot, E, Exp = 0;
f1 = str[0]; //符号
nDot = str.find('.'); //返回小数点的下标
num1 = str[nDot - 1]; //第一位数字
E = str.find('E');
num2.assign(str.begin() + nDot + 1, str.begin() + E);//小数点后面的数字
f2 = str[E + 1]; //指数符号
num3.assign(str.begin() + E + 2, str.end());//指数
Exp = stoi(num3); //将指数从字符串形式变为整数形式
if (f1 == "-")
res += "-";
if (f2 == "-")
{
res += "0.";
res.insert(res.end(), Exp - 1, '0');//中间插入0
}
else if (f2 == "+")
{
if (num2.length() <= Exp)//小数位不足,则直接末尾加0;
num2.insert(num2.end(), Exp - num2.length(), '0');
else//小数位多余幂次,则小数点后移
num2.insert(num2.begin() + Exp, 1, '.');
}
res += num1 + num2;
cout << res << endl;
return 0;
}