[英]Pass \ in command line arguments of C++
I am working on a C++ program where one of the command line arguments needs to be a passed a regex. 我正在使用一个C ++程序,其中命令行参数之一需要传递一个正则表达式。 For example:
abc.exe --option ab\\[0\\]
例如:
abc.exe --option ab\\[0\\]
When I access the option value from inside the program, it becomes ab\\\\[0\\\\]
which becomes a different regex. 当我从程序内部访问选项值时,它变成
ab\\\\[0\\\\]
,这成为另一个正则表达式。 Inside the program when I try to replace \\\\[
with \\[
using boost::replace_all
, the result is [
which also is not the intended output for me. 在程序内部,当我尝试使用
boost::replace_all
将\\\\[
替换为\\[
,结果为[
这也不是我想要的输出。
So, any suggestions on how to pass and retain \\[
this while passing it through command line arguments 因此,有关如何通过命令行参数传递和保留
\\[
这的任何建议
You can quote the parameter: 您可以引用参数:
abc.exe --option "ab\[0\]"
Or use the shell escape sequence: 或使用外壳转义序列:
abc.exe --option ab\\[0\\]
Did you try these? 你尝试过这些吗?
It was a problem with how visual studio displays the symbol. Visual Studio如何显示符号是个问题。 When I looked on the ASCII code of the symbol, it was alright.
当我查看该符号的ASCII码时,还好。 Thanks @ScottK for helping me to debug this through your comments
感谢@ScottK帮助我通过您的评论进行调试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.