소스 : Dev-C++ 로 작성, 컴파일
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
vector<string> m_stringList;
string str = "abc";
m_stringList.push_back(str);
str = "zdagasx";
m_stringList.push_back(str);
str = "csertwd";
m_stringList.push_back(str);
str = "ew897qw";
m_stringList.push_back(str);
sort(m_stringList.begin(), m_stringList.end());
for(int i = 0; i < m_stringList.size(); i++)
{
printf("%sn", m_stringList[i].c_str());
}
system("PAUSE");
return 0;
}
결과 :
abc
csertwd
ew897qw
zdagasx
계속하려면 아무 키나 누르십시오 . . .
... 소트에 관해선 말그대로 정상적으로 실행됩니다만...
혹시나 모르니까 buffer (char배열)에 내용을 받기 전에 ZeroMemory나 memset로 싹 청소를 한번씩 해줘보시는것도 괜찮을지 모르겠습니다. 보통 버퍼에 문자열 받는거는 자체적으로 청소한번 해주는거같던데...