SAS/MenuUtils.cpp
2022-07-04 00:31:52 +08:00

29 lines
538 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include"MenuUtils.h"
void checkOptInput(int& opt, int low, int high) {
printf(">>>请输入选项(%d-%d)", low, high);
while (!(cin >> opt) || (opt < low) || (opt > high)) {
cout << "输入选项错误!请重新输入:";
cin.clear();
while (cin.get() != '\n');
}
}
string doubleToString(double num) {
char* buf;
int dec, sign;
buf = _fcvt(num, 2, &dec, &sign);
string str;
if (sign) str += "-";
int i;
for (i = 0; i < dec; i++) {
str += buf[i];
}
str += ".";
for (; i < strlen(buf); i++) {
str += buf[i];
}
return str;
}