本文介绍了反斜杠导致问题C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在C ++中以这样的字符串使用反斜杠:
I'm trying to use back slash in C++ in a string like this :
HWND hwnd = FindWindowA(NULL, "C:\Example\App.exe");
因此对于此示例,我将得到以下错误/警告:未知转义序列:'\ E'""未知转义序列:'\ A'.由于我需要输入窗口的确切名称,是否有任何方法可以避免使用反斜杠或阻止编译器将其解释为转义序列"?
So for this example I would get these errors/warnings :"unknown escape sequence: '\E'" "unknown escape sequence: '\A'" .Since I need to type in the exact name of the window , is there any way to avoid using back slashes or stop the compiler from interpreting them as "escape sequences" ?
推荐答案
您必须正确地逃避它们,C ++ 11添加了原始字符串可简化此操作:
You have to escape them properly, C++11 added raw string which eases this thing:
HWND hwnd = FindWindowA(NULL, R"(C:\Example\App.exe)");
其他则手动完成:
HWND hwnd = FindWindowA(NULL, "C:\\Example\\App.exe");
这篇关于反斜杠导致问题C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!