文字列を1文字ずつ列挙して、見つけた'/'を'¥'に変換します。
#include <tchar.h>
#include <iostream>
#include <string>
#include <windows.h>
/*
'/'を'¥'マークに変換する
*/
std::wstring ConvertWebPathToFilePath
(
std::wstring strString // 変換したい文字列
)
{
std::wstring strRet;
std::wstring::iterator ite = strString.begin();
std::wstring::iterator iteEnd = strString.end();
while (ite != iteEnd) {
TCHAR wChar = *ite++;
// '/'を'¥¥'に変換する
if (L'/' == wChar) {
strRet += L'¥¥';
continue;
}
strRet += wChar;
}
// 変換結果を返す
return(strRet);
}
/*
'/'を'¥'マークに変換する
*/
int _tmain
(
int argc
, _TCHAR* argv[]
)
{
// ロケール変更(wcoutでユニコードを出力する為)
std::wcout.imbue(std::locale("", std::locale::ctype));
// '/'を'¥'マークに変換する
std::wstring strRet = ConvertWebPathToFilePath( L"http://www.wabiapp.com/WabiSampleSource/windows/" );
// 結果の出力
std::wcout << L"¥"" << strRet.c_str() << L"¥"" << std::endl;
// 正常終了
return( 0 );
}
"http:\\www.wabiapp.com\WabiSampleSource\windows\"