【发布时间】:2018-03-30 18:57:29
【问题描述】:
在我正在创建的程序上搜索潜在错误时,我得到了 “[错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive]。”
错误来自我的 while 循环,我打算让程序只接受来自用户的以下输入。现在,我正在考虑为此使用一个数组。
我应该如何解决这个问题?如果有人有更多详细信息,我很乐意通过展示我的身份(最近)向他们提供。
int main () // While using one of the three functions to make conversions,
// the program will create the table based on following information.
{
char dimension;
double u1, u2;
int starting_value, ending_value, increment, startingUnitDigits,
endingUnitDigits;
cout << "-------------------------------------------------------------------------------------------------";
cout << "Please answer the following questions as they appear.";
cout << "Check spelling, use correct abbreviation for units of measurement, and avoid negative values.";
cout << "-------------------------------------------------------------------------------------------------";
cout << "Enter the dimensions from the following choices: length, mass and time. (i.e.: 'length,' 'Length').";
while (!(dimension == "length" || dimension == "Length" || dimension == "mass" || dimension == "Mass" || dimension == "time" || dimension == "Time"))
{
cout << "----------------------------------------------------------------------------------------------------";
cout << "Error! Input for Dimension, " << dimension << ", was either an invalid choice or typed incorrectly.";
cout << "Please know that this programs accepts length, mass, and time only!";
cout << "----------------------------------------------------------------------------------------------------";
cout << "Enter the dimensions from the following choices: length, mass and time. (i.e.: 'length,' 'Length').";
cin >> dimension;
【问题讨论】:
-
char dimension它的 1 个字符,您正在检查维度 == "length" .. 等 -
@Catholic_Ryanite 使用 std::string 维度;而不是 char 维度;并在循环之前初始化它
-
顺便说一句,您的标题具有误导性,并且与问题没有真正的关系,格式并不是真正的问题(除了可能的意图不佳)
-
使用
while (true) { cin >> dimension; if (...) { print error message } else {break;}} -
@tobi303 如果他改成
std::string,则默认为空字符串。
标签: c++ arrays string file while-loop