我正在尝试从字符串中获取第一个数字,并且仅获取第一个数字。我找到的解决方案找到了所有数字。
我尝试使用下面的代码,但没有弄清楚。
/\d./g
我有一个像IN9000这样的字符串,我只想得到9。该字符串在字符串中的第三个位置将具有不同的值。
答案 0 :(得分:2)
删除int main()
{
double cost;
int hoursParked;
char choice;
cout << "Do you have a car, truck, or bus?" << endl << "c = car, t = truck, b = bus" << endl;
cin >> choice;
bool isCar;
switch (choice) {
case 'c':
isCar = true;
break;
case 't':
case 'b':
isCar = false;
break;
default:
cerr << "invalid vehicle type: " << choice << "\n";
return 1;
};
cout << endl << "How long were you parked?" << endl;
cin >> hoursParked;
if (isCar) {
if (hoursParked <= 2) {
cost = 1.25 * hoursParked;
}
else {
cost = 1.25 * hoursParked;
cost = 1.50 * (hoursParked - 2) + cost;
}
}
cout << "Here is your receipt " << 1.25 * cost << endl;
}
(全局)标志:
g