Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back slash causing problems c++

I'm trying to use back slash in C++ in a string like this :

HWND hwnd = FindWindowA(NULL, "C:\Example\App.exe");

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" ?

like image 281
Vlada Misici Avatar asked Apr 15 '26 10:04

Vlada Misici


2 Answers

You have to escape them properly, C++11 added raw string which eases this thing:

HWND hwnd = FindWindowA(NULL, R"(C:\Example\App.exe)");

else do it manually:

HWND hwnd = FindWindowA(NULL, "C:\\Example\\App.exe");
like image 194
Jarod42 Avatar answered Apr 17 '26 00:04

Jarod42


You should escape that properly:

HWND hwnd = FindWindowA(NULL, "C:\\Example\\App.exe");

For a full list of all escape sequences, check this:

https://en.cppreference.com/w/cpp/language/escape

like image 30
artm Avatar answered Apr 16 '26 22:04

artm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!