得到错误偏离'342'和'200'和'214

Getting errors stray ‘342’ and ‘200’ and ‘214’(得到错误偏离342和200和214)

本文介绍了得到错误偏离'342'和'200'和'214'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为一个简单的游戏编写一个程序,但是在 Ubuntu 13.10(Saucy Salamander).

I'm trying to write a program for a simple game, but I am getting errors, stray ‘342’ and ‘200’ and ‘214’, using g++ and gedit in Ubuntu 13.10 (Saucy Salamander).

代码是:

#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
";
        char player_choice;
        cin >>‌ player_choice;

        if ( player_choice != 'C' || player_choice != 'D' || player_choice != 'Q' )
        {
            cout << "Illegal input.
enter an other
";
            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!
";
        more = false;
    }
}

终端输出为:

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' )
       ^

我什至试图编译这个:

#include <iostream>

using namespace std;

int main()
{
    char a;
    cin >>‌ a;
}

终端又说:

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

我该如何解决这个问题?

How can I fix this?

请注意,我昨晚安装了 Ubuntu.

Note that I installed Ubuntu last night.

推荐答案

您使用的是 代码中 >> 之后的零宽度非连接符 字符.这是一个 Unicode 字符,以 UTF-8 编码为三个字符,其值为 0x2e0x800x8c(或以 8 为基数,<代码>342200214).这可能是因为您从使用这些特殊字符的文档(HTML 网页?)中复制并粘贴了一些代码.

You are using a Zero Width Non Joiner character after the >> in your code. This is a Unicode character that is encoded in UTF-8 as three characters with values 0x2e, 0x80, 0x8c (or in base 8, 342, 200, 214). This probably happened because you copy and pasted some code from a document (HTML web page?) that uses those special characters.

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

The C++ language requires that the whole program uses mostly the ASCII encoding, except for the content of strings or character literals (that may be in a implementation-dependent encoding). So to fix your problem, make sure that you only use simple ASCII space, quotes, double quotes and not smart characters.

这篇关于得到错误偏离'342'和'200'和'214'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:得到错误偏离'342'和'200'和'214

基础教程推荐