一道关于向文件输出的题目!

xchfriend 2003-09-14 02:21:18
请用c++编程:

将键盘上敲打的字符存放到文件中去(该文件为C:\temp.txt)!
...全文
39 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
积木 2003-09-15
  • 打赏
  • 举报
回复
楼上的哥们好像喜欢将 using namespace std;
放在主函数里啊,有什么好处吗?
aflyinghorse 2003-09-15
  • 打赏
  • 举报
回复
呵呵
我只是稍微修改一下pengzhenwanli(紫气日盈)的代码
using namespace std;放在主函数里 我觉得没什么额外的好处

他的作用是把std中的声明限制在main函数的作用域中
aflyinghorse 2003-09-14
  • 打赏
  • 举报
回复
按 ctrl+Z 结束输入
aflyinghorse 2003-09-14
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
fstream file;
file.open( "c:\\temp.txt",ios_base::out);
string str;
while(getline(cin, str, '\n'))
{
file << str << '\n';
}
file.close();
}
pengzhenwanli 2003-09-14
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
string buffer;
fstream file;
file.open( "c:\\temp.txt",ios_base::out);
int a;
while(a = cin.get())
{
buffer+= a;
}
file<<buffer;
file.close();
}

}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧