半角アルファベットを全角アルファベットへ変換します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <tchar.h> #include <iostream> #include <string> #include <algorithm> #include <windows.h> /* 半角アルファベットを全角アルファベットへ変換する */ std::wstring WStringToAll ( std::wstring oString ) { std::wstring::iterator ite = oString.begin(); std::wstring::iterator iteEnd = oString.end(); while ( ite != iteEnd ) { /* 'a~z'なら'a~z'に変換する */ if ( ( L 'a' <= *ite ) && ( L 'z' >= *ite ) ) { *ite += ( L 'a' - L 'a' ); } /* 'A~Z'なら'A~Z'に変換する */ else if ( ( L 'A' <= *ite ) && ( L 'Z' >= *ite ) ) { *ite += ( L 'A' - L 'A' ); } // 次の文字へ ite++; } // 正常終了 return ( oString ); } /* 半角アルファベットを全角アルファベットへ変換する */ int _tmain ( int argc , _TCHAR* argv[] ) { // 標準出力へユニコードを出力する setlocale ( LC_ALL, "Japanese" ); // 半角アルファベットを全角アルファベットへ変換する std::wstring oResultStr = WStringToAll( L "ABCDEFGabcdefg" ); // 結果を表示 std::wcout << oResultStr.c_str() << std::endl; // 正常終了 return ( 0 ); } |
ABCDEFGabcdefg