我是一個新的程序員衛生組織碰上,我不明白 一個compilling錯誤,我希望能有人爲能幫助我理解爲什麼 誤差C++語法編譯錯誤
31 F:\C++ Programming\Chapter 13\Exercises\Exercise 32.cpp 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> >*)(&letter))), ((const char*)"a")) || 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> >*)(&letter))), ((const char*)"e"))) || 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> >*)(&letter))), ((const char*)"i"))) || 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> >*)(&letter))), ((const char*)"o"))) || letter'
代碼
#include <iostream>
#include <string>
using namespace std;
main()
{
string word = "";
string letter = " ";
int count = 7;
string temp = "";
int x = 0;
//end declair
cout << "Please enter a word: ";
getline(cin, word);
count = word.length();
letter = word.substr(0, 1);
if(letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u")
{
word.insert(count, "-way");
cout <<"word starting with vowel is "<<word<<endl;
}
while(letter != "a" && letter != "e" && letter != "i" && letter != "o" &&
letter != "u"|| letter == "y")
{
x = 0;
while(x < count)
{
letter = word.substr(0, 1);
word.insert(count, "-");
if(letter == "a" || letter == "e" || letter == "i" || letter == "o" ||//error is here
letter || "u"|| letter == "y") //error iss here
{
temp = letter;
cout <<letter <<" ------------------------"<<endl;
word.erase(x, 1);
cout <<word <<" ------------------------"<<endl;
word.insert(x, letter);
cout <<word <<" ------------------------"<<endl;
letter = word.substr(0, 1);
}
x += 1;
}
cout <<"word starting with letter is "<<word<<endl;
}
system("pause");
}
你會用'isVowel'功能好得多。指出這些錯誤在哪裏出現也是有幫助的。 – chris