Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExtThes_Uniquify
//Title of this code //Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86 #define UNICODE #include <iostream> #include <algorithm> #include <functional> #include <vector> #include <string> #include <cctype> #include <array> #include <cwchar> #include <windows.h> #include <atlstr.h> using namespace ATL; using namespace std; vector<CString> Unique(const wchar_t**words, int cWords) { vector<const wchar_t *> v(words, words + cWords); sort(v.begin(), v.end(), [](const wchar_t *strA, const wchar_t *strB) { return wcscmp(strA, strB) < 0; }); v.erase(std::unique(v.begin(), v.end(), [](const wchar_t *strA, const wchar_t *strB) { return 0 == wcscmp(strA, strB); }), v.end()); v.erase(remove_if(v.begin(), v.end(), [](const wchar_t *str){ return 0 == CString(str).Trim().GetLength(); }), v.end()); vector<CString> vs(v.size()); transform(v.begin(), v.end(), vs.begin(), [](const wchar_t* w){ return w; }); return vs; } vector<CString> Unique(vector<CString> &vWords) { sort(vWords.begin(), vWords.end(), [](const CString strA, const CString strB) { return strA < strB; }); vWords.erase(std::unique(vWords.begin(), vWords.end(), [](const CString strA, const CString strB) { return strA == strB; }), vWords.end()); vWords.erase(remove_if(vWords.begin(), vWords.end(), [](CString str){ return 0 == str.Trim().GetLength(); }), vWords.end()); return vWords; } int main() { // remove duplicate elements (normal use) const wchar_t* words [] = {L"ZUERICH",L"Aachen",L"Berlin",L"zuerich",L"Berlin",L"Aachen",L"Frankfurt",L"Zuerich", L" ", L" ", L" ", L""}; vector<CString> strings = {L"ZUERICH",L"Aachen",L"Berlin",L"zuerich",L"Berlin",L"Aachen",L"Frankfurt",L"Zuerich", L" ", L" ", L" ", L""}; vector<CString> vords = Unique( words, _countof( words)); for (const CString &i : vords) std::wcout << i.GetString() << L"|"; std::wcout << L"%\n"; Unique(strings); for (const CString &i : strings) std::wcout << i.GetString() << L"|"; std::wcout << L"$\n"; }
run
|
edit
|
history
|
help
0
PTaHHHa
sample ptr and obj ex
RecursiveDivide
vc++ bug?
VC++ '-flag Fail
Overload resolve function pointer
Wide string conversion with multibyte chars
For NULL-embedded strings, CStringT::Find() produces what you may not expect
No UD
const_pointer_cast