このコードが期待どおりに出力されない理由を理解するのに少し苦労していますか? 何か案は?
出力: ? あなたは
期待される: ?こんにちは、
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
stack<string> sentence;
sentence.push("Hello,");
sentence.push("how");
sentence.push("are");
sentence.push("you");
sentence.push("?");
for (int i=0; i<sentence.size(); ++i) {
cout << sentence.top() << " ";
sentence.pop();
}
cout << endl;
return 0;
}