杂散 '\342' 在 C++ 程序中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2340930/
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
Stray '\342' in C++ program
提问by neuromancer
I'm getting these errors in my program after pasting in some code:
粘贴一些代码后,我在我的程序中收到这些错误:
showdata.cpp:66: error: stray ‘2' in program
showdata.cpp:66: error: stray ‘0' in program
showdata.cpp:66: error: stray ‘5' in program
showdata.cpp:66: error: stray ‘\' in program
showdata.cpp:66: error: stray ‘2' in program
showdata.cpp:66: error: stray ‘0' in program
showdata.cpp:66: error: stray ‘5' in program
showdata.cpp:67: error: stray ‘2' in program
showdata.cpp:67: error: stray ‘0' in program
showdata.cpp:67: error: stray ‘5' in program
showdata.cpp:67: error: stray ‘\' in program
showdata.cpp:67: error: stray ‘2' in program
showdata.cpp:67: error: stray ‘0' in program
showdata.cpp:67: error: stray ‘5' in program
Here are the two lines that are causing the errors.
这是导致错误的两行。
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
How to fix this?
如何解决这个问题?
回答by LiraNuna
The symbol ”
is not "
. Those are called 'smart quotes' and are usually found in rich documents or blogs.
符号”
不是"
。这些被称为“智能报价”,通常可以在丰富的文档或博客中找到。
回答by hlovdal
The lines
线条
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
have some "special" kind of double quotes, try the following:
有一些“特殊”类型的双引号,请尝试以下操作:
size_t startpos = str.find_first_not_of(" \t");
size_t endpos = str.find_last_not_of(" \t");
回答by Saurav Sahu
It is worth mentioning here (for whoever lands on this page just like me) that this sort of error message error: stray ‘\xyz' in program
can appear with any other character or symbol that is not recognized by the compiler as a legal one.
值得一提的是(对于像我一样登陆此页面的任何人),此类错误消息error: stray ‘\xyz' in program
可能与任何其他未被编译器识别为合法字符或符号的字符或符号一起出现。
Sharing my personal experience:
分享我的个人经验:
- bool less<const char?>(const char? a, const char? b)
- bool less<const char*>(const char* a, const char* b)
Former one is copy-pasted from a PDF file. It doesn't compile..
前一个是从 PDF 文件复制粘贴的。它不编译。.
Later one compiles as expected.
稍后按预期编译。
回答by cokedude
You can use the sed command to fix these issues.
您可以使用 sed 命令来修复这些问题。
This will give you a quick preview of what will be replaced.
这将使您快速预览将要替换的内容。
sed s/[”“]/'"'/g File.txt
sed s/[”“]/'"'/g File.txt
This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.
这将进行替换并将替换内容放入名为 WithoutSmartQuotes.txt 的新文件中。
sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt
sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt
This will overwrite the original file.
这将覆盖原始文件。
sed -i ".bk" s/[”“]/'"'/g File.txt
sed -i ".bk" s/[”“]/'"'/g File.txt