A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

So....

844 views · started by 323 ·
#1
So....
How can you add the "\" character in a C++ program?

Like, say you're adding a program path in a program.

like say,


stringName = "C:\Users\Blablabla";


How do you make it accept the backslash character as part of the string, instead of interpreting it as something like "\n"?
#2
lolol

'\\' double-backslash or use ASCII son
#3
lolol

'\\' double-backslash or use ASCII son


Can you use something like U+005C (unicode) or do you just use a double backslash?
#4
Can you use something like U+005C (unicode) or do you just use a double backslash?


ummm. Unicode has nothing to do with backslash characters. it's an entirely different character set. Just use double backslash. Or ASCII (which is the proper character encoding/format).
#6
Use those corresponding ASCII character decimals in the table and simulate it through C++'s built-in ASCII support.

Ex. string hi = "lol\92";

Printing that variable should result in "lol\" being displayed in the console. Although '\\' is obviously more shorthanded.
#7
Use those corresponding ASCII character decimals in the table and simulate it through C++'s built-in ASCII support.

Ex. string hi = "lol\92";

Printing that variable should result in "lol\" being displayed in the console.


Oh sweet :D thanks! I'll probably use the \\, but thanks for telling me that C++ had built-in ASCII support. Didn't know that :o
#8
Yeah, most if not all modern languages support the ASCII standard. The more precedent focus right now is including Unicode support since not too many languages support that by default.
#9
There are some useful libraries that support UNICODE characters though, which is nice.

I use an IDE that has cross-platform support for UNICODE so I don't worry about it.
#10
Sinza_ wrote:
There are some useful libraries that support UNICODE characters though, which is nice.

I use an IDE that has cross-platform support for UNICODE so I don't worry about it.


Does that IDE happen to be CodeBlocks? Also Unicode is not an acronym so it's usually not all capitalized. I'm sure you're aware and that you're just typing it like that out of preference, but I thought I'd point that out.
#11
Does that IDE happen to be CodeBlocks? Also Unicode is not an acronym so it's usually not all capitalized. I'm sure you're aware and that you're just typing it like that out of preference, but I thought I'd point that out.


He uses Qt