September 18, 2008
The same sort function used to sort STL vector can be used for sorting arrays also. Surprised? Sometimes life is easier than we expect.
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int MyArray[] = {10, 9, 8, 7, 6};
sort(MyArray, MyArray + 5);
for (int i = 0; i < 5; ++i)
{
cout << MyArray[i] <<'\n';
}
return 0;
}
2 Comments |
C++, VC++ 2005 | Tagged: C++, sort, sort a vector, sort an array, sort array, sort function |
Permalink
Posted by cppkid
September 18, 2008
See the following code segment.
CString myCString = _T("Hello");
const TCHAR* myCharString = LPCTSTR(myCString);
Some Background Info
- TCHAR will be evaluated to char if _UNICODE is not defined. Otherwise it will be evaluated to wchar.
- LPCTSTR is also a data type which is nothing but const char* or const wchar*, depending on whether _UNICODE defined or not.
- CString has a constructor which accepts TCHAR*.
- The macro _T will make the supplied string neutral. That is, if _UNICODE is defined, the string will be in 16 bit unicode format, otherwise in 8 bit ANSI format.
Leave a Comment » |
C++, VC++ 2005 | Tagged: ansi, CString, cstring to char*, CString to TCHAR*, cstring to wchar*, TCHAR, unicode |
Permalink
Posted by cppkid