c ++语法编译错误

时间:2013-08-16 01:42:53

标签: c++ syntax compiler-construction dev-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");
}

3 个答案:

答案 0 :(得分:1)

letter || "u"应该是:letter == "u"

答案 1 :(得分:1)

|| letter || "u")//

//尝试

|| letter == "u")//

答案 2 :(得分:-1)

使用字符串的成员函数比较

letter.compare("a")