文字列に対していくつかの操作を実行し、結果を返す次の関数を定義しました。
string Message()
{
string result = "";
int l;
result += "1";
for(l = 0; l < routers; l++)
{
result += " " + table[l];
}
cout<<result<<endl;
return result;
}
ただし、返された結果をwhileループでフェッチ(フェッチと名付けることができる場合)し、それを出力すると、それらは同じではありません!!
while(true)
{
string a = Message();
cout<<a<<endl;
//do some operation
}
結果:
1 12 13 15 21 1 (printed out before exiting the function)
1 12 13 15 21 (after fetching)
その理由は何ですか?