65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
template <typename T>
T write(ostream &os, const T &v)
{
os << v;
return 0;
}
int main()
{
write(cout, "wo");
cout << endl;
ofstream of;
of.open("x.txt");
write(of, "ai");
// 怎么没输出? 未实现题目要求
stringstream ss;
write(ss, "ni");
cout << endl;
return 0;
}
stringstream ss;
write(ss, "ni");
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
template <typename T>
void write(ostream &os, const T &v)
{
os << v;
// return 0;
}
int main()
{
write(cout, "wo");
cout << endl;
ofstream of;
of.open("x.txt");
write(of, "ai");
// 怎么没输出? 未实现题目要求
stringstream ss;
write(ss, "ni");
cout << ss.str()<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
template <typename T>
void write(ostream &os, const T &v) // void类型,下面不提供返回值
{
os << v;
}
int main()
{
write(cout, "wo");
cout << endl;
ofstream of;
of.open("xxx.txt"); // 在.cpp文件夹下,自动建立一个名为 .cpp的文本文档
// of.open("d:/woaini.txt"); // 像这样指出绝对路径也可以
write(of, "ai");
of.close();
// 不论有无上句 of.close(), if语句都输出......... ? 怎么测试有没关闭?
if (of)
cout << ".........." << endl;
stringstream ss;
write(ss, "niaiwoma");
cout << ss.str() << endl; // 加上此句后,实现了输出
return 0;
}