Description 補足程式,使得下麵程式輸出的結果是: 100 ~~~~ include include using namespace std; // Your Code Here string Print1() { return " "; } int Print2() { return 1 ...
Description
補足程式,使得下麵程式輸出的結果是:
****100
#include <iostream>
#include <string>
using namespace std;
// Your Code Here
string Print1()
{
return "****";
}
int Print2()
{
return 100;
}
int main()
{
cout << Print1 << Print2 << endl;
return 0;
}
Output
****100
解法如下:
#include <iostream>
#include <string>
using namespace std;
ostream& operator<<(ostream& out, string (*p)())
{
out << (*p)();
return out;
}
ostream& operator<<(ostream& out, int (*p)())
{
out << (*p)();
return out;
}
string Print1()
{
return "****";
}
int Print2()
{
return 100;
}
int main()
{
cout << Print1 << Print2 << endl;
return 0;
}