微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在字符串中分隔数字

如何解决如何在字符串中分隔数字

#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;    

struct Calculations //structure to hold the numbers and operators from 'equation' 
{
    double num1;
    char   operators;
    double num2;
    double answer;
};
Calculations myCalculationArray[SIZE]; // the array of calculations
int main()
{
    
    while (i = 0; i <= 5; i++;)
    {
        cout << "Enter equation: \n";

        getline(cin,equation);

        cout << equation;
    }
}

好吧,所以我试图建立一个计算器,用户输入一个像“ 22/2”这样的方程式,然后像把第一个数字分配给num1 ='22'并将operator ='/'赋给运算符一样等

解决方法

因为这似乎是学生的一项家庭作业,所以我将为您提供计算器的另一种解决方案,您可以根据需要进行修改;)

if let url = URL(string: "https://wa.me/\(item.contact!)?text=Testing test"),//cant work
UIApplication.shared.canOpenURL(url) {
   UIApplication.shared.open(url,options: [:])
}
,

您可以借助strtok,strchr来解析字符串(分离出操作符号和两个数字操作数)。 要将数字字符串(例如“ 34”)转换为34,可以使用atoi和atod等函数。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。