Getting errors stray ‘342’ and ‘200’ and ‘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 编码为三个字符,其值为 0x2e
、0x80
、0x8c
(或以 8 为基数,<代码>342、200
、214
).这可能是因为您从使用这些特殊字符的文档(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
基础教程推荐
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01