[파일명: TestStringFindInList.cpp]------------------------------------------------
// Filename: TestStringFindInList.cpp
//
// Compile: cl /clr TestStringFindInList.cpp
// Execute: TestStringFindInList
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
void PrintArray(List<String^>^ arr);
bool Contains(String^ s)
{
return s->IndexOf("셋") >= 0;
}
int main(array<String^> ^args) {
List<String^>^ words = gcnew List<String^>( gcnew array<String^> { "하나", "둘", "셋", "넷", "다섯", "여섯" } );
int where;
Console::Write("list: ");
PrintArray(words);
where = words->FindIndex(gcnew Predicate<String^>(Contains));
if (where >= 0) {
Console::Write("발견! ");
Console::WriteLine("Next word of 셋 in list: {0}", words[where+1]);
}
Console::WriteLine("Sorting...");
words->Sort();
Console::Write("list: ");
PrintArray(words);
where = words->FindIndex(gcnew Predicate<String^>(Contains));
if (where >= 0) {
Console::Write("발견! ");
Console::WriteLine("Next word of 셋 in list: {0}", words[where+1]);
}
return 0;
}
void PrintArray(List<String^>^ arr) {
Console::Write("[");
for (int i = 0; i < arr->Count - 1; i++) {
Console::Write("{0}, ", arr[i]);
}
if (arr->Count > 0)
Console::Write("{0}", arr[arr->Count - 1]);
Console::WriteLine("]");
}
------------------------------------------------
컴파일> cl /clr testStringFindInList.cpp
실행> TestStringFindInList
list: [하나, 둘, 셋, 넷, 다섯, 여섯]
발견! Next word of 셋 in list: 넷
Sorting...
list: [넷, 다섯, 둘, 셋, 여섯, 하나]
발견! Next word of 셋 in list: 여섯
'프로그래밍 > C++' 카테고리의 다른 글
윈도우에 MinGW, gmp, mpfr 설치하고 테스트하기 (0) | 2012.12.31 |
---|---|
C++ 언어로 GMP 라이브러리를 이용하여 30! 까지 정확하게 계산하기 (7) | 2010.08.13 |
스트링 배열에서 스트링 찾기(find) for .NET with Visual C++/CLI (0) | 2009.04.30 |
명령행 인자 처리 예제 for .NET with C++/CLI (0) | 2009.04.29 |
Hello 예제 for .NET with C++/CLI (0) | 2009.04.29 |