String 将字符串转换为int(?)c++;
是否有其他方法可以在stod()上使用替代方案?或者移除它。这是我们的教授提出的挑战 我们有一些代码限制,比如不允许使用数组、向量、stod、stoi等。但我尝试使用stod()并提交它以查看他是否看不到它,这就是为什么我提出了以下代码:String 将字符串转换为int(?)c++;,string,integer,String,Integer,是否有其他方法可以在stod()上使用替代方案?或者移除它。这是我们的教授提出的挑战 我们有一些代码限制,比如不允许使用数组、向量、stod、stoi等。但我尝试使用stod()并提交它以查看他是否看不到它,这就是为什么我提出了以下代码: #include <iostream> #include <string> using namespace std; int main() { string cInputNames, cOutput, cquantity, cp
#include <iostream>
#include <string>
using namespace std;
int main() {
string cInputNames, cOutput, cquantity, cprice;
double quantity = 0, sum = 0, sum1 = 0;
do {
cout << "Product name: ";
cin >> cInputNames;
if (cInputNames == "x" || cInputNames == "X") {
cout << " - OFFICIAL RECEIPT -\n";
cout << "Qty\tProduct name\tPrice\n";
cout << cOutput;
cout << "Total\n";
cout << sum1 << " item(s)\t\t" << sum;
break;
}
cout << "Quantity: ";
cin >> cquantity;
cout << "Price : ";
cin >> cprice;
cOutput += cquantity + '\t' + cInputNames + "\t\t" + cprice + '\n';
quantity = stod(cquantity);
sum += quantity * stod(cprice);
sum1 += quantity;
} while (1);
}
#包括
#包括
使用名称空间std;
int main(){
字符串cInputNames、cOutput、cquantity、cprice;
双倍数量=0,总和=0,总和=0;
做{
cout>cInputNames;
如果(cInputNames==“x”| | cInputNames==“x”){
库特