C++错误:警告:多字符字符常量/a用于用法
C++ error: warning: multi-character character constant/atof usage
C++新手。有人能向我解释一下我收到的错误信息是什么意思吗?或者我为什么会收到它们?非常感谢。
#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'
编辑:感谢大家对while(input!='exit')的建议。有人能检查一下我在计算部分是否正确使用了atof吗?我对我所拥有的没有任何计算。如果输入45,则得到k=0或250。
不应该使用类型为int
和实现定义值的多字符文字,而应该在该语句中使用字符串文字
}while(input != 'exit');
那一定有
}while(input != "exit");
使用:
while(input != "exit"); // Notice double quotes
'exit'
给出"警告:多字符字符常量"
您需要使用" "
将其与字符串文字进行比较
'a'
是一个字符常量。CCD_ 5也是一个字符常数;形式上,它是一个多字符的字符常量。这里要使用的是"exit"
,它是一个字符串文字。
相关文章:
- C++模板,用于通过常量引用和原始指针传递向量
- 算法不适用于非常量对象的const_iterator
- 多字符常量警告
- const_cast<字符 *>(字符* 常量) 不是左值?
- 常量字符数组模板与字符常量* 函数重载
- 用于共享常量的头文件或库
- 如何检查字符常量是否符合ASCII
- 从字符串数组转换为字符* 常量
- 字符常量或字符串常量
- 字符常量数组为空,即使已为其赋值 [C++]
- 如何创建 ' 字符常量
- 如何编写完全可移植的 4 字节字符常量的编译时初始化
- Cin 不适用于字符数组
- 我得到以下错误:[警告]多字符字符常量
- C++错误:警告:多字符字符常量/a用于用法
- C11/C++11 宏,用于将常量字符串与文本整数相关联
- 避免在用于区分常量和非常量模板函数中的代码重复
- 字符常量和函数名称的 sizeof() 背后的逻辑
- 如何在 C 中将多字符常量转换为整数
- 如何举例来反驳“==”用于比较“常量字符*”的用法