Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gaiiden

What's with "\" ???

This topic is 6444 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does C++ not like it when I do this: LPSTR path = "C:\"; ??? I get errors like "newline in constant" and "missing ;" on the next line down. When I take out the "\" in the string, I get no errors! Why is this? I've never had this problem before. I also noticed when putting it inot a define like this: #define PATH "C:\PFiles\C++\" // these comments aren't green!! the comments afterwards aren't comments! anyone know what's going on here? ============================== "Need more eeenput..." - #5, "Short Circuit" ============================== Edited by - Gaiiden on 10/29/00 2:34:30 PM

Share this post


Link to post
Share on other sites
Advertisement
In C/C++, using a \ in a string indicates an escape sequence. For example:

\n - newline
\t - tab
\" - double-quotes

To get a backslash character, just use it twice in a row, like this: \\. So a valid filename would look like this:

#define PATH "c:\\pfiles\\C++\\"

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.


Edited by - Ironblayde on October 29, 2000 3:42:29 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
\ starts a sequence ( in c/c++ ) ( like \n \r \t \" ).

If you want to use only a \ you have to write \\ ( so it looks like this

LPSTR path = "C:\\";

)

That''s all.

Share this post


Link to post
Share on other sites
C was designed on a unix system, so you can use / instead of \\. \\ will not work if you are on a unix system only on windows. new compilers should be clever enough to make the switch, be I would not bet on it.

char* pcString[Size] = "c:/directory/file";

Share this post


Link to post
Share on other sites
quote:

C was designed on a unix system, so you can use / instead of \\.



That has nothing to do with C, it has to do with the operating system.

Share this post


Link to post
Share on other sites
even on windows, the forward slash "/" is the directory separator. the backslash is basically only used in the shell.

Share this post


Link to post
Share on other sites
quote:

the backslash is basically only used in the shell.



It's used in many more places than that, most Windows programs use \ (Explorer for example).

Edited by - Muzzafarath on October 30, 2000 8:14:44 AM

Share this post


Link to post
Share on other sites
Backslash is used under DOS, in case you have not been using computers for long enough to have used it, and the forward slash is not a valid delineation character for DOS. And the / being used in C is to do with the language. If you try using that under DOS it will _NOT_ work. The reason the www uses / as its delineation character is because it is based on UNIX, which as mentioned before used / as its delineation character.



Please state the nature of the debugging emergency.


sharewaregames.20m.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So to sum up, in C/C++ if you want a forward slash in a string, use /.
If you want a backslash in a string, use \\.




Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!