【发布时间】:2012-02-26 03:46:19
【问题描述】:
我正在尝试处理一些代码...
#include <iostream>
#include <string>
int main()
{
std::cout << "Hello. Welcome to Delicious Drive Up. What would you like to order?\n";
std::cout << "\nOur menu is-";
std::cout << "...";
std::cout << "\nOrder here > ";
std::string choice;
std::getline(cin, choice);
if (choice == 'hamburger' || choice == 'Hamburger')
{
std::cout << "We don't have any ham. Is a Chickenburger all right? y/n. > ";
std::string opt;
std::getline(cin, opt);
if (opt == 'y' || opt == 'Y' || opt == 'yes' || opt = 'Yes')
{
std::cout << "Here's your chickenburger.";
}
}
}
这是改编自我编写的 Bash 脚本,是我的第一个 C++ 程序之一。当我编译它时,它会出现这些错误......
test.cpp:19:15: warning: character constant too long for its type
test.cpp:19:40: warning: character constant too long for its type
test.cpp:23:44: warning: multi-character character constant
test.cpp:23:59: warning: multi-character character constant
test.cpp: In function ‘int main()’:
test.cpp:19: error: no match for ‘operator==’ in ‘choice == 1919378802’
test.cpp:19: error: no match for ‘operator==’ in ‘choice == 1919378802’
test.cpp:23: error: no match for ‘operator==’ in ‘opt == 'y'’
test.cpp:23: error: no match for ‘operator==’ in ‘opt == 'Y'’
test.cpp:23: error: no match for ‘operator==’ in ‘opt == 7955827’
您能解释一下这些是什么意思以及如何解决它们吗?
编辑:我现在收到一条新的错误消息...
.test.cpp: In function ‘int main()’:
.test.cpp:23: error: no match for ‘operator||’ in ‘((std::operator== [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(& opt))), ((const char*)"y")) || std::operator== [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(& opt))), ((const char*)"Y"))) || std::operator== [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(& opt))), ((const char*)"yes"))) || opt’
.test.cpp:23: note: candidates are: operator||(bool, bool) <built-in>
【问题讨论】:
标签: c++ compiler-errors operators