#目的
IntIntクラスのメンバ変数"int_1"と"int_2"の値を
"( int_1の値 , int_2の値 )"と出力したい。
以下のソースコードのどの部分を直せばよいでしょうか。
また、危険な書き方等ありましたら指摘して頂けると幸いです。
#ソースコード
cpp
1#include <cstdio> 2#include <string> 3#include <iostream> 4#include <sstream> 5 6struct IntInt 7{ 8 int int_1=0; 9 int int_2=0; 10 11 IntInt() = default; 12 constexpr IntInt(const int int1_, const int int2_) :int_1(int1_), int_2(int2_) {} 13 14 operator const char*() 15 { 16 std::stringstream ss; 17 ss << '(' << int_1 << ',' << int_2 << ')'; 18 return ss.str().c_str(); 19 } 20}; 21 22int main() 23{ 24 IntInt ii(0, 0); 25 std::cout << ii << std::endl; 26 printf("%s\n", ii); 27 28 return 0; 29}
#上記コードの実行結果
フ bー0シク( O`オ ー0シクー ヌx)・マ (null)

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。