掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
stringstreamをCString(もしくはstringやchar)で取得するには? (ID:71265)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
/* option: -EHsc -DAFX_DLL - or - -EHsc -DAFX_DLL -DUNICODE -D_UNICODE */ #include <afxwin.h> // CString #include <iostream> // cout, wcout #include <iomanip> // setw, setfill #include <sstream> // stringstream, wstringstream using namespace std; #ifndef UNICODE int main() { CString text = "あいう"; stringstream s_txt; s_txt << setw(10) << setfill(' ') << text; text = s_txt.str().c_str(); //★ cout << '[' << static_cast<const char*>(text) << ']' << endl; ; } #endif > setfillを使おうとするからいけなかったんですね… ↓いけなくないですがー #ifdef UNICODE #include <locale> int main() { wcout.imbue(locale("japanese")); CString text = "あいう"; wstringstream s_txt; s_txt << setw(10) << setfill(L' ') << static_cast<const wchar_t*>(text); text = s_txt.str().c_str(); //★ wcout << '[' << static_cast<const wchar_t*>(text) << ']' << endl; ; } #endif
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.