如何在C ++中禁用转义序列 [英] How to disable the escape sequence in C++

查看:60
本文介绍了如何在C ++中禁用转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++处理许多文件,我必须在源代码中这样写文件名:"F:\\ somepath \\ subpath \\ myfile" ,我想知道是否有什么方法可以消除在字符串文字上下文中键入"\\"来获取字符"\"的可能性,即,我希望我可以只写"F:\ somepath \ subpath \ myfile" 而不是无聊的.

I use C++ to process many files, and I have to write the file name in source code like this: "F:\\somepath\\subpath\\myfile", I wonder that if there's any way to get rid of typing "\\" to get a character '\' in string literal context, i.e, I hope I can just write "F:\somepath\subpath\myfile" instead the boring one.

推荐答案

解决方案:

  1. 使用C ++ 11字符串文字: R(F:\ somepath \ subpath \ myfile)"

使用boost :: path带有正斜杠:他们将验证您的路径并提出问题的例外.

Use boost::path with forward slashes: They will validate your path and raise exceptions for problems.

boost::filesystem::path p = "f:/somepath/subpath";
p /= "myfile";

  • 只需使用正斜杠;Windows应该了解它们.

  • just use forward slashes; Windows should understand them.

    这篇关于如何在C ++中禁用转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆