したがって、次のような単純な対話型プログラムがあるとします。
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#define cout os
int main() {
stringstream os;
cout << "If you would like to continue, type 'Continue'" << '\n';
string line;
while (cin >> line) {
if (line == "Continue") {
cout << "If you would like to continue, type 'Continue'" << '\n';
}
else { break; }
}
cout << "Program ended." << '\n';
cout << os.str();
return 0;
}
標準出力に出力されるすべての行が cout << os.str() によってプログラムの最後に出力されるように、ディレクティブ「#define」を含めることができるようにするにはどうすればよいですか?また、最終的な「cout」を「os」にしますか?最後にosで代わりにprintfを使用しようとしましたが、「printfへの一致する関数呼び出しがありません」というトラブル/コンパイラエラーが発生しています。
私の質問が理にかなっていることを願っています。これがすでに尋ねられている場合はお詫びしますが、ここで見つけることができませんでした.