Microsoft KB Archive/312844

= The Visual C++ System::String class does not support greater than and less than operators =

Article ID: 312844

Article Last Modified on 1/12/2006

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q312844



This article refers to the following Microsoft .NET Framework Class Library namespace:
 * System.String



SYMPTOMS
The Visual C++ System::String class does not support the < and > operators.



CAUSE
This behavior occurs because of the large number of sort variations that you can use with the < and > operators.



RESOLUTION
You can use the Compare, CompareOrdinal, CompareTo, and Equals methods to compare string objects. These methods can honor or ignore case, language, or culture-specific information.



STATUS
This behavior is by design.



MORE INFORMATION
The following Visual C++ example demonstrates how to compare two strings: //compiler option : cl /clr
 * 1) using 
 * 2) include 

using namespace System;

// This is the entry point for this application. int _tmain(void) { String* myString= &quot;1234&quot;; int rc = myString->CompareTo(&quot;abcd&quot;); if (rc>0) Console::WriteLine(&quot;1234 is greater than abcd&quot;); else if (rc==0) Console::WriteLine(&quot;1234 is equal to abcd&quot;);

else Console::WriteLine(&quot;1234 is less than abcd&quot;);

return 0; } Note You must add the common language runtime support compiler option (/clr:oldSyntax) in Visual C++ 2005 to successfully compile the previous code sample. To add the common language runtime support compiler option in Visual C++ 2005, follow these steps:
 * 1) Click Project, and then click   Properties.

Note  is a placeholder for the name of the project.
 * 1) Expand Configuration Properties, and then click General.
 * 2) Click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project setting in the right pane, click Apply, and then click OK.

For more information about the common language runtime support compiler option, visit the following Microsoft Web site:

/clr (Common Language Runtime Compilation)

http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx

Keywords: kbprb KB312844

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.