私のコードはテスト用です。型変換が不可能な場合に stringstream が例外をスローするかどうかを確認しようとしています。
以下は私のコードです。お使いの環境で確認できます。
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int main() {
stringstream stream("432.23");
char c = 0;
try {
if(!stream>>c) {
cout<<"Error happend"<<endl;
return 0;
}
}
catch(...) {
cout<<"Exception happend"<<endl;
}
cout<<"c="<<c<<endl;
return 0;
}
出力は c=^@ です
エラーを見つけるべきではありませんか?