如何在输出之前添加数字?

时间:2017-02-23 21:16:17

标签: c++ string variables numbers output

我正在为我的班级开发C ++程序,而且我不确定规范。我想在字符串orderCode的输出之前添加数字但不确定如何执行此操作。例如,输入" BF12"将是" 12黑森林蛋糕。"我试图将蛋糕的数量和数量包含在一个单独的字符串变量中。谁能给我一些指示?任何事情都会非常感激。

这是我的代码:

#include <iostream>
using namespace std;

int main() {

string orderCode;
string repeat = "y";
while ("y" == repeat) {

cout << "\nWelcome to the Great Cake company!\n";
cout << "\nEnter the cake order code: ";
cin >> orderCode;

int quantity = orderCode.length() - 1;


if (orderCode == "BF2")
{ (cout << orderCode.substr(quantity) << " Black Forest cakes");
}

if (orderCode == "CC")
  { (cout << "Carrot cakes");
}

  if (orderCode == "CM")
     { (cout << "Chocolate Mint cakes");
}

  if (orderCode == "DF")
     { (cout << "Devil's Food cakes");
}

  if (orderCode == "GC")
     { (cout << "German Chocolate cakes");
}

  if (orderCode == "PC")
     { (cout << "Pumpkin Cheesecakes");
}

  if (orderCode == "RC")
     { (cout << "Rum cakes");
}

  if (orderCode == "T")
     { (cout << "Tiramisu cakes");
}

cout << "\nOrder more? (y/n) ";
cin >> repeat;
}


return 0;
}

0 个答案:

没有答案