获取错误stray'\342'和'\200'和'\214' [英] getting errors stray ‘\342’ and ‘\200’ and ‘\214’
问题描述
hi我试图编写一个程序为一个简单的游戏,但使用g ++和gedit在ubuntu 13.10的错误stray'\342'和'\200'和'\214。
代码是:
hi I'm trying to write a program for a simple game but getting errors stray ‘\342’ and ‘\200’ and ‘\214’ using g++ and gedit in ubuntu 13.10. the code is:
#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;
}
}
并且终端输出是:
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
任何人都可以帮我吗?
请注意,我昨晚安装了ubuntu。
note that I was installed ubuntu last night.
推荐答案
您正在使用>> 之后的.info / info / unicode / char / 200c / index.htm>零宽度非联接这是一个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 require 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.
这篇关于获取错误stray'\342'和'\200'和'\214'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!