C++ 错误:程序中的“\302”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5167656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: stray '\302' in program
提问by underdoeg
I'm using Code::Blocks on Ubuntu 10.10. I have connected a Mac keyboard and set the keyboard settings to "Swiss German Mac". Now whenever I write an equals sign, followed by a space (something like width = 100) I get the error message error: stray '\302' in program.
我在 Ubuntu 10.10 上使用 Code::Blocks。我已经连接了 Mac 键盘并将键盘设置设置为“Swiss German Mac”。现在,每当我写一个等号,后跟一个空格(类似于宽度 = 100)时,我都会收到错误消息 error:stray '\302' in program.
I know this error means that there is a non standard character in the text file.
我知道这个错误意味着文本文件中有一个非标准字符。
When I delete the space character the program compiles just fine. So that means Code::Blocks adds some sort of special character. But I can't see why this happens. Anybody have an idea.
当我删除空格字符时,程序编译得很好。所以这意味着 Code::Blocks 添加了某种特殊字符。但我不明白为什么会发生这种情况。任何人都有一个想法。
What character does '\302' stand for?
'\302' 代表什么字符?
[UPDATE] I got a little further investigating the problem. I get this stray when I use the combo shift+space. Now that I know it doesn't happen that often anymore. But it's still rather annoying especially when writing code... Anybody know if there is a way to turn off this combo in X11?
[更新] 我进一步调查了这个问题。当我使用组合 shift+space 时,我得到了这个。现在我知道它不再经常发生了。但这仍然很烦人,尤其是在编写代码时……有人知道是否有办法在 X11 中关闭此组合?
[SOLVED] Thanks to Useless's answer, I was able to solve the "issue". It's more of a feature actually. Shift+space created a spacenolinebreak by default. So by changing the xmodmap with
[已解决] 感谢 Useless 的回答,我能够解决“问题”。它实际上更像是一个功能。默认情况下,Shift+space 会创建一个空格换行符。所以通过改变 xmodmap
xmodmap -e "keycode 65 = space space space space space space"
this behavior was overridden and everything works fine now.
此行为已被覆盖,现在一切正常。
THANKS!
谢谢!
采纳答案by Useless
Since you're sure it's caused by hitting shift+space
, you can check what X itself is doing by. First, run xev
from the command line, hit shift+space
and check the output. For example, I see:
由于您确定它是由击中引起的shift+space
,您可以检查 X 本身在做什么。首先,从命令行运行xev
,点击shift+space
并检查输出。例如,我看到:
$ xev
KeyPress event, serial 29, synthetic NO, window 0x2000001,
root 0x3a, subw 0x0, time 4114211795, (-576,-249), root:(414,593),
state 0x0, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyPress event, serial 29, synthetic NO, window 0x2000001,
root 0x3a, subw 0x0, time 4114213059, (-576,-249), root:(414,593),
state 0x1, keycode 65 (keysym 0x20, space), same_screen YES,
XLookupString gives 1 bytes: (20) " "
XmbLookupString gives 1 bytes: (20) " "
XFilterEvent returns: False
...
Then, run xmodmap -pk
and look up the keycode (space should be 65 as above, but check your xev output).
If you see something like
然后,运行xmodmap -pk
并查找键码(空格应为 65,如上,但请检查您的 xev 输出)。如果你看到类似的东西
65 0x0020 (space)
Then X isn't doing this. On the other hand, if I pick a character key which ismodified by shift
, I see something like this:
那么 X 不这样做。在另一方面,如果我选择哪一个字符键是通过修改shift
,我看到这样的事情:
58 0x006d (m) 0x004d (M)
If you have two or more keysyms for your keycode, X is the culprit. In that case, something like xmodmap -e 'keycode 65 space'
should work.
如果您的键码有两个或更多键符,则 X 是罪魁祸首。在这种情况下,类似的东西xmodmap -e 'keycode 65 space'
应该可以工作。
回答by Tugrul Ates
\302 stands for the octal representation of byte value the compiler encountered. It translates to 11000010 in binary, which makes me think it's the start of a two byte utf-8 sequence. Then this sequence must be:
\302 代表编译器遇到的字节值的八进制表示。它以二进制形式转换为 11000010,这让我认为它是两字节 utf-8 序列的开始。那么这个序列必须是:
11000010 10??????
Which encodes the binary unicode point 10??????, which can be anything from U+80 to U+BF.
哪个编码二进制 unicode 点 10??????,可以是从 U+80 到 U+BF 的任何内容。
Several characters starting from U+80 are special spaces and breaks which usually are not shown inside a text editor.
从 U+80 开始的几个字符是特殊的空格和分隔符,通常不会在文本编辑器中显示。
Probably it's not your editor but Xorg, that emits these characters due to your keyboard settings. Try switching to a generic US keyboard and test if the problems persists.
由于您的键盘设置,可能不是您的编辑器而是 Xorg 发出这些字符。尝试切换到通用美式键盘并测试问题是否仍然存在。
回答by David Rodríguez - dribeas
I have seen this type of issue when copying and pasting from web pages or other electronic documents. The common culprits would be invalid quotes like ` instead of ', or something alike. Try to use the compiler error to guide you into where in the file the error might be.
我在从网页或其他电子文档复制和粘贴时遇到过此类问题。常见的罪魁祸首是无效的引号,例如 ` 而不是 ' 或类似的东西。尝试使用编译器错误来引导您了解错误可能在文件中的哪个位置。
回答by tp1
I've seen this problem in my linux box with finnish keyboard. Also happens with emacs etc. I don't have good solution for it, but guess reports about the fact that it happens elsewhere are also useful...
我在我的带有芬兰语键盘的 linux 盒子中看到了这个问题。也发生在 emacs 等上。我没有很好的解决方案,但猜测关于它发生在其他地方的事实的报告也很有用......
回答by Kerrek SB
If you open your file in Emacs and set-buffer-file-coding-system to something like "unix" or some ascii variety, then when you try to save, it'll warn you that the buffer contains unrepresentable characters and points you to them so you can fix them.
如果您在 Emacs 中打开文件并将缓冲区文件编码系统设置为类似“unix”或某些 ascii 变体,那么当您尝试保存时,它会警告您缓冲区包含无法表示的字符并指向您它们,以便您可以修复它们。
回答by bcag2
I had the same issue by modified a us-ascii example file. So I convert it in utf-8, here are gnu/linux command :
通过修改 us-ascii 示例文件,我遇到了同样的问题。所以我将它转换为 utf-8,这里是 gnu/linux 命令:
iconv -c -t us-ascii -f utf-8 source_file -o dest_file
and then add my modifications… no more errors! to verify initial encoding, use
然后添加我的修改......没有更多错误!验证初始编码,使用
file -i source_file
I should add a non ascii character to allow iconv do the job !!??
我应该添加一个非 ascii 字符以允许 iconv 完成这项工作!!??
回答by Mario
That sounds like some kind of encoding issue. I haven't used code::blocks for years, so not sure if it allows you to pick different encodings. How about opening your code file with gedit and saving it as UTF-8, then try again? But sounds rather strange that you get such an issue using space characters.
这听起来像是某种编码问题。我多年没有使用 code::blocks,所以不确定它是否允许您选择不同的编码。用 gedit 打开你的代码文件并将其保存为 UTF-8,然后再试一次怎么样?但是听起来很奇怪,您使用空格字符会遇到这样的问题。
回答by unwind
'\302'
is C notation for the octal number 3028, which equals C216and 19410. So it's not ASCII.
'\302'
是八进制数 302 8 的C 符号,它等于 C2 16和 194 10。所以它不是ASCII。
Which character it maps to depends on the encoding. In Latin-1, it's the ? character, for instance.
它映射到哪个字符取决于编码。在拉丁语 1 中,它是 ? 字符,例如。