これはC++プログラムのコードスニペットです。C++で 'ostringstream'オブジェクトを管理するには?
string TwoSeries::getArrays()
{
ostringstream outIndex;
ostringstream outValueA;
ostringstream outValueB;
string stA;
string stB;
string valueA;
string index;
int *arA;
int * arB;
string valueB;
for(int x = 0; x < 200; x++)
{
outIndex << x;
index = outIndex.str();
arA = getArrayA();
outValueA << *(arA + x);
valueA = outValueA.str();
arB = getArrayB();
outValueB << *(arB + x);
valueB = outValueB.str();
stA += index + ":" + valueA + " ";
stB += index + ":" + valueB + " ";
}
// return "Series A: \n"+stA+ "\n"+"Series B: \n"+ stB;
return index;
}
この関数は、最後のインデックスは、文字列にint型から変換され、それは199でなければなりませんしかし、その代わりに、このオブジェクトのoutIndex "を連結にすべての数字(文字列)を1つの文字列に、結果としてのようなものを与えて返す必要がありますこれは1234567891011121314151617 ... 198199です。最後の数字は199です。最後の数字だけを出力する完全なループの後に関数を強制するには、代わりにすべての数字が必要です。これを行う方法?
「ostringstream」とは何と思いますか?なぜあなたが望まない値を挿入するのですか? –