c++如何将这串字符分成四个double型实数0.000000000000E+00 4.847967065871E-04-1.023181539495E-11 0.000000000000E+00
时间: 2024-01-06 12:03:45 浏览: 33
可以使用字符串分割函数将这串字符分割成四个字符串,然后再将每个字符串转换为double类型的实数。
例如,可以使用C++中的stringstream:
```c++
#include <iostream>
#include <sstream>
int main() {
std::string str = "0.000000000000E 00 4.847967065871E-04-1.023181539495E-11 0.000000000000E 00";
std::stringstream ss(str);
double num1, num2, num3, num4;
ss >> num1 >> num2 >> num3 >> num4;
std::cout << "num1: " << num1 << std::endl;
std::cout << "num2: " << num2 << std::endl;
std::cout << "num3: " << num3 << std::endl;
std::cout << "num4: " << num4 << std::endl;
return 0;
}
```
输出:
```
num1: 0
num2: 0.000484797
num3: -1.02318e-11
num4: 0
```
相关问题
用c++在字符串“# 1 2171 1728.0 25”中提取25为double型实数
Hello, World!”中找到字符'O'的位置。
可以使用字符串函数中的index()方法来查找'O'这个字符在字符串中出现的位置。代码如下:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
char ch = 'O';
char *p;
p = strchr(str, ch);
printf("字符 %c 在字符串中的位置是:%d\n", ch, (int)(p-str));
return 0;
}
```
输出结果为:字符 O 在字符串中的位置是:4。
c++如何将有科学计数法的字符串转化为double型实数
可以使用Java中的Double.parseDouble()方法来将科学计数法的字符串转化为double型实数。
例如,将字符串"1.23E-5"转化为double型实数,可以使用如下代码:
```
String str = "1.23E-5";
double num = Double.parseDouble(str);
```
其中,parseDouble()方法会自动识别字符串中的科学计数法,并将其转化为对应的double型实数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)