// string_t.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include "string_t.h" int main(int argc, char* argv[]) { ComBSTRing str(L"Hello, world!"); std::wcout << str.c_str() << std::endl; str.append(L" Wake up and smell coffee"); std::wcout << str.c_str() << std::endl; str.insert(6, L" cruel"); std::wcout << str.c_str() << std::endl; str.replace(6, sizeof(L" cruel") /sizeof(wchar_t) -1, L" happy"); std::wcout << str.c_str() << std::endl; wchar_t* pszHello = L"Hello, World!"; str = pszHello; std::wcout << L"Initialize string from pszHello of char:\t" << str << std::endl; for(int i = 0 ; i < str.size() ; ++i) std::wcout << L"str[" << i << L"] = 0x" << std::hex << str[i] << std::endl; str.erase(str.begin() + 3, str.end() - 3); // Erase all but first and last three letters std::wcout << L"Erase all letters but first and last three:\t" << str << std::endl; str.insert(3, (wchar_t*)pszHello); // Insert original text at 3rd position std::wcout << L"Insert original pszHello of chars at 3rd position:\t" << str << std::endl; str.erase(0, 3); // Erase first three letters (pos, number) std::wcout << L"Erase first three letters (pos, number):\t" << str << std::endl; str.erase(str.end() - 3, str.end()); // Erase last three letters (iterator, iterator) std::wcout << L"Erase last three letters (iterator, iterator):\t" << str << std::endl; std::wcout << L"'" << str << L"' == '" << pszHello << L"' ? " << std::boolalpha << (str == pszHello) << std::endl; str.clear(); // Erase all. std::wcout << L"Is string with length " << str.length() << L" empty? " << std::boolalpha << str.empty() << std::endl; std::wcout << L"\nMake Release out of Debug file name " << std::endl; ComBSTRing bstrFile(L"C:\\Temp\\Debug.txt"); std::wcout << L"\nDebug File Name: " << bstrFile << std::endl; static const ComBSTRing bstrToReplace(L"\\Debug."); ComBSTRing::size_type pos = bstrFile.find_last_of(bstrToReplace); if (pos ==ComBSTRing::npos) bstrFile.assign(L"C:\\Temp\\Debug.xml"); else bstrFile.replace(pos -bstrToReplace.length() +1, bstrToReplace.length(), L"\\Release."); std::wcout << L"\nRelease File Name: " << bstrFile << std::endl; bstrFile = ComBSTRing(); // check assignment to the empty string return 0; }