指定した文字列を検索して、wstringを2つに分離します。
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
#include <string>
#include <iostream>
#include <windows.h>
/*
wstringを指定した文字列で分離する
*/
void SpritWString
(
std::wstring oString
, std::wstring oSpliter
, std::wstring& oOutput1
, std::wstring& oOutput2
)
{
std::wstring::size_type iExtPos = oString.find( oSpliter );
if ( -1 != iExtPos ) {
oOutput1 = std::wstring( oString.begin(), oString.begin() + iExtPos );
oOutput2 = std::wstring( oString.begin() + iExtPos + oSpliter.size(), oString.end() );
}
else {
oOutput1 = oString;
oOutput2 = L"";
}
}
int _tmain
(
int argc
, _TCHAR* argv[]
)
{
// 標準出力にユニコード出力する
setlocale( LC_ALL, "Japanese" );
std::wstring oOutput1;
std::wstring oOutput2;
// wstringを指定した文字列で分離する
SpritWString( L"sprit-wstring", L"-", oOutput1, oOutput2 );
// 標準出力へ出力する
std::wcout << oOutput1 << std::endl;
std::wcout << oOutput2 << std::endl;
// 正常終了
return( 0 );
}
sprit
wstring