스트링 배열 정렬(sorting)하기 for .NET with Visual C++
[파일명: testSortApp.cpp]------------------------------------------------
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
void printArray(array<String^>^ arr);
int main(int argc, char *argv[]) {
array<String^>^ arr = gcnew array<String^>(argc - 1);
for (int i = 1; i < argc; i++) {
arr[i-1] = gcnew String(argv[i]);
}
Array::Sort(arr);
printArray(arr);
}
void printArray(array<String^>^ arr) {
Console::Write("[");
for (int i = 0; i < arr->Length - 1; i++) {
Console::Write("{0}, ", arr[i]);
}
if (arr->Length > 0)
Console::Write("{0}", arr[arr->Length - 1]);
Console::WriteLine("]");
}
------------------------------------------------
Visual C++의 경우:
컴파일> cl /clr testSortApp.cpp
실행> testSort one two thee four five
[five, four, one, three, four]
실행> testSortApp 하나 둘 셋 넷 다섯
[넷, 다섯, 둘, 셋, 하나]