Hi,

Is anyone familiar with this problem in BorlandBuilderC++:

void Print(AnsiString Path){
Label1->Caption=Path.c_str();
}
...
Print("C:\Directory1\Directory2\Music.mp3");

When I pass this string to Print(AnsiString) and try to display it in Label1, I lose all '\' signs and text in Label1 looks like this : "C:Directory1Directory2Music.mp3"

Why is this like that?

Thank you!

You did not escape the back-slash character. All strings/literals will have this behaviour as the first back-slash will escape the following character so inorder to have a back-slash, you must escape it with another. You either need to do:

C:\\Directory1\\Directory2\\Music.mp3

OR:
C:/Directory1/Directory2/Music.mp3

Command prompt will complain about the same thing to you. char's will behave the same and so will char*'s that's what I mean by literals. This is why \0 is the same as 0 which is known as the NULL character; usually appended to the literals to terminate them.

Edited 4 Years Ago by triumphost

This question has already been answered. Start a new discussion instead.