如何在字符串中分隔数字

问题描述

#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等函数。