Click to See Complete Forum and Search --> : S character on a string


mager
August 6th, 2004, 02:22 PM
Can anyone tell me what exactly is the difference between these two lines?

System::Console::Write("Foo");
System::Console::Write(S"Foo");

I'm having a very difficult time unearthing anything on this anywhere at all...

I know what the L character does for the wchar_t type, but what does the S character do????

lhayes00
August 6th, 2004, 02:59 PM
Hi,

In MC++ the S indicates that the following string is to be treated as a String*, a string literal. Thus, it should be more efficient to say Console::Write(S"Hi");

Hope this helps!

Best Regards,
Lea Hayes

mager
August 6th, 2004, 03:06 PM
"hello" in C++ is considered a char* by default, so it needs to be built, and then cast into a String*. Using the S directly manufactures a String* skipping all the char* overhead. This String* is of the type System::String from the .NET MC++ library and not std::string.

Is this correct?

lhayes00
August 6th, 2004, 03:13 PM
Hi,

That's it, the String* literal generated by prefixing your string with the letter S creates an MC++ String* and not a std::string. However th L prefix still works the same as before with good old C++.

Best Regards,
Lea Hayes

mager
August 6th, 2004, 03:39 PM
Thanks for your help. It's quite disturbing to note that this is not posted anywhere I could find in the MSDN help. Ugh :)

Paul McKenzie
August 6th, 2004, 03:49 PM
Thanks for your help. It's quite disturbing to note that this is not posted anywhereThat is because what you have there is not part of the normal Visual C++ package -- those are .Net classes. .Net questions are off-topic here (there is a .Net forum).

Regards,

Paul McKenzie

mager
August 6th, 2004, 04:04 PM
Because of the L symbol for wide characters I thought it might be a part of the spec for regular C++ so I posted the question here.

Andreas Masur
August 7th, 2004, 04:55 AM
[ Moved thread ]