• 締切済み

wstringについて

以下のプログラムを実行すると「Abnormal program termination」となってしまいます。 何故なのでしょうか? どこか間違っているところがあるのでしょうか? #include <iostream> #include <string> int main(void) { std::wstring ws = L"文字列"; std::wcout.imbue(std::locale("japanese")); std::wcout << ws << std::endl; return 0; } 環境はWindowsXP/Borland C++ Compiler 5.5です。 よろしくお願いします。

みんなの回答

  • sho1get
  • ベストアンサー率57% (20/35)
回答No.1

ここのブログサイトにそれらしいことが書いてありましたよ http://rpgincpp.cocolog-nifty.com/blog/

関連するQ&A

  • std::wstringの継承

    #include<iostream> #include<string> #include <stdlib.h> #include <locale.h> #include <boost/lexical_cast.hpp> using boost::lexical_cast; using namespace std; VisualC++2008ExpressEditionで文字や数字を簡単に扱えるクラスを今作ろうとしていて以下のように作ってみました。 class multiString:public std::wstring{ public:   multiString(const wchar_t *ws){     /* multiString class自体に代入 */   } }; しかし、このwchar_tをクラスに代入する処理として、 multiString(const wchar_t *s)std::wstring(s); とすると、「error C2082: 仮パラメータ 's' が再定義されました。」となりますし、 multiString(const wchar_t *s)*this=s; とすると、例外が発生してしまします。 wstringだったら、簡単に代入処理として出来るのですが、継承した場合はどの様に実装すればいいのでしょうか? 宜しくお願いします。

  • C++のファイルの分割について教えてください。

    分割したプログラムの書き方を練習中なのですが、 下のようなプログラムを書いて、ビルドしようとしたら失敗します。 どこが悪いのか、教えていただけないでしょうか? (5)\test30\Debug\test30.exe : fatal error LNK1120: 外部参照 1 が未解決です。 1>test30 - エラー 2、警告 0 ========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ========== //test30.cpp #include <iostream> #include "sub.h" int main(void) { std::cout<<"メインプログラムです。"<<std::endl; sub1(); sub2(); return 0; } ------------------------------------------------------------- //sub1.cpp #include <iostream> void sub1(void) { std::cout<<"サブ1です。"<<std::endl; } ------------------------------------------------------------- //sub2.cpp #include <iostream> void sub1(void) { std::cout<<"サブ2です。"<<std::endl; } --------------------------------------------------------------- //sub.h void sub1(void); void sub2(void);

  • STLのwstring型から BSTR型 への変換

    // STLのwstring型から BSTR型 への変換てこんな感じでいいのでしょうか? #pragma warning(push,3) #include <string> #pragma warning(pop) #include <Windows.h> void main(void) {  std::wstring sString1 = L"This is STL_wstring";  std::wstring sString2;  BSTR sWork1 = ::SysAllocString(L"This is BSTR\n");  BSTR sWork2;  sString2 = sWork1;  sWork2 = ::SysAllocString(sString1.c_str()); // ここ  ::SysFreeString(sWork1);  ::SysFreeString(sWork2); }

  • std::wstringのメモリリークについて教えてださい

    C++でプログラムを書いていたところメモリリークしているのを発見しました。 そこでなんとかメモリリークしている箇所を特定してみたのですが、なんとstd::wstringとstd::stringがメモリリークしているようです。 (UNICODEとマルチバイト文字に対応させるため両方でプログラムかいています) ローカル変数で関数さえ抜ければメモリからは消滅するはずのstd::wstringやstd::stringがメモリリークしているのは何か原因でもあるのでしょうか? よろしくおねがいします。

  • コンパイルができません

    先ほど質問させていただきましたが、もう一度質問させていただきます。 BCC Developerというソフトを使って参考書のとおり次のようなプログラムをコンパイルしようとしました。 #include <string> #include <iostream> using namespace std; int main(){ string s1; s1 = "こんにちわ"; count << s1 << endl; } この文章は正確だと思うのですがコンパイルができません。 コンパイラはborlandの5.5バージョンを使っています どうすればいいのでしょうか?

  • Borland C++ Compiler 5.5

    ここで教えてもらってBorland C++ Compiler5.5とCPadをつかってるんですが、 #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; rreturn 0; } と入れると、 「hello.exeがありません」(helloは保存データの名前) と出るんです。 古いバージョン専用のスクリプトなのですか? それとも設定ミスですか? 教えてください。

  • 結果を報告しない?(void)

    #include<iostream> #include<string> using namespace std; void Aisatu(string n){ cout<<n<<"さん、こんばんわ"<<endl; } int main() { Aisatu("鈴木"); } 上のプログラムで、C++の学習書に「void」とは「この関数は結果をどこにも報告しない、ということ」と書いてありますが、私の理解では下のAisatu("鈴木");という外部の文字列を受け取りcout<<nに「報告」しているように感じられます。どうか解釈がうまくいきますようにご教授いただけないでしょうか。よろしくお願いします。

  • この文章正確ですか?

    #include <string> #include <iostream> using namespace std; int main(){ string s1; s1 = "こんにちわ"; count << s1 << endl; } これをコンパイルしようとしてもできません。 どこが間違っているのでしょうか?

  • shared_ptr クラスについて

    shared_ptrクラスを使いたいのですが、使えません、どうしてでしょうか?ソースはこれです。 #include<iostream> #include <string> #include <fstream> #include<memory> using namespace std; class SMonster{ string name; int power; public: SMonster(); SMonster(int p); ~SMonster(){ }; void SetPower(int p); int GetPower(SMonster& t)const; void walk(const string& str); int GetPoint(void)const; }; class B {}; class D : public B {}; int main(void) { shared_ptr<D> sp0(new D); SMonster m(200); SMonster n(100); std::cout<<m.GetPower(m)<<std::endl; std::cout<<n.GetPower(n)<<std::endl; ShowWindow(10); }

  • テンプレート関数に関して質問です。

    テンプレート関数に関して質問です。 wstringとstringに対して、似たような処理を行いたいので、template関数を使ってうまく定義できないかと思ったのですが、例えば、 #include<string> template<class T> void hoge(T &s){ s="a"; } void main(void){ std::string str; hoge(str); } の場合、class TがwstringだとL"a"としないといけないのですが、Tによってこれを変えることは可能でしょうか? また、できれば、hogeに想定外の変数を入れられたくないので、hogeをtypedefのようなのりで、 void foo(std::string &s); void foo(std::wstring &s); と定義しておきたいのですが何か良いアイデアはないでしょうか? 当然、hogeはstaticグローバル変数のように外部からはアクセスできないようにしておきたいのです。 よろしくお願いします。

専門家に質問してみよう