C++ C++;错误:警告:多字符字符常量/atof用法
C++新手。有人能给我解释一下我收到的错误信息是什么意思或者为什么我会收到它们吗?多谢各位C++ C++;错误:警告:多字符字符常量/atof用法,c++,C++,C++新手。有人能给我解释一下我收到的错误信息是什么意思或者为什么我会收到它们吗?多谢各位 #include <iostream> #include <string> int main () { std::string
#include <iostream>
#include <string>
int main () {
std::string input;
double f, k;
/* edit: codes to go inside the do while loop */
std::cout << "\nEnter Fahrenheit temperature or 'exit' to end program: ";
std::getline(std::cin, input);
do {
f = std::atof(input.c_str()); //convert string input to double
k = (f + 459.67) * (5/9);
std::cout << "Entered Fahrenheit temperature is: " << f << std::endl;
std::cout << "Temperature in Kelvin is " << k << std::endl << std::endl;
}while(input != 'exit'); //program runs until input is 'exit'
return 0;
}
Errors:
t.cc:21:19: warning: multi-character character constant
t.cc: In function `int main()':
t.cc:21: error: no match for 'operator!=' in 'input != 1702390132'
#包括
#包括
int main(){
std::字符串输入;
双f,k;
/*编辑:进入do while循环的代码*/
std::cout使用:
“退出”
给出“警告:多字符常量”
您需要使用“”将其与字符串文字进行比较。'a'
是一个字符常量。'exit'
也是一个字符常量;形式上,它是一个多字符字符常量。这里要使用的是'exit'
,它是字符串文字。在该语句中应使用字符串文字而不是字符文字
}while(input != 'exit');
这是应该的
}while(input != "exit");
input!=“exit”
应该是input!=“exit”
。注意引号。
}while(input != "exit");