得到错误迷失'\ 342'和'\ 200'和'\ 214'

ArM*_*Mor 2 c++ ubuntu g++

嗨,我正在尝试为一个简单的游戏编写一个程序但是在ubuntu 13.10中使用g ++和gedit得到错误'\ 342','\'200和'\ 214'.代码是:

#include <iostream>
#include <cctype>

using namespace std;

char all_d()
{
    return 'D';
}

int main()
{
    bool more = true;
    while ( more )
    {
        cout << "enter C to cooperate, D to defect, Q to quit\n";
        char player_choice;
        cin >>? player_choice;

        if ( player_choice != 'C' || player_choice != 'D' || player_choice != 'Q' )
        {
            cout << "Illegal input.\nenter an other\n";
            cin >> player_choice;
        }

        char  cpu_choice = all_d();

        cout << "player's choice is " << player_choice << endl;
        cout << "cpu's choice is " << cpu_choice << endl;
    }

    if ( player_choice == 'Q' )
    {
        cout << "Game is Over!\n";
        more = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

和终端输出是:

IPD.cpp:18:3: error: stray ‘\342’ in program
   cin >>? player_choice;
   ^
IPD.cpp:18:3: error: stray ‘\200’ in program
IPD.cpp:18:3: error: stray ‘\214’ in program
IPD.cpp: In function ‘int main()’:
IPD.cpp:29:47: error: ‘end’ was not declared in this scope
   cout << "cpu's choice is " << cpu_choice << end;
                                               ^
IPD.cpp:32:7: error: ‘player_choice’ was not declared in this scope
  if ( player_choice == 'Q' )
       ^
Run Code Online (Sandbox Code Playgroud)

甚至试图编译这个:

#include <iostream>

using namespace std;

int main()
{
    char a;
    cin >>? a;
}
Run Code Online (Sandbox Code Playgroud)

和终端再次说:

a.cpp:8:2: error: stray ‘\342’ in program
  cin >>? a;
  ^
a.cpp:8:2: error: stray ‘\200’ in program
a.cpp:8:2: error: stray ‘\214’ in program
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我吗?

请注意我昨晚安装了ubuntu.

Syl*_*sne 10

您在代码中使用了零宽度非连接>>.这是在UTF-8作为三个字符编码有值的Unicode字符0x2e,0x80,0x8c(或在基座8 \342,\200,\214).这可能是因为您从使用这些特殊字符的文档(html网页?)中复制并粘贴了一些代码.

C++语言要求整个程序主要使用ASCII编码,但字符串或字符文字的内容(可能是依赖于实现的编码)除外.因此,要解决您的问题,请确保您只使用简单的ASCII空格,引号,双引号而不是智能字符.

  • *"除了字符串或字符文字的内容"* C++ 还允许在注释中使用非 ASCII 字符。 (2认同)