注册 登录
编程论坛 VC.NET论坛

[求助]关于ofstream的问题

lblovett 发布于 2007-05-08 15:01, 2183 次点击

下面是我写的程序,为了了解ofstream的用法,可就是调试不成功,麻烦大家帮我改下,我的编程环境是.net 2003
#include "iostream.h"
#include "fstream.h"
#include "string.h"
#include "stdafx.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
ofstream ofs("data.dat");

ofs << "Hello!" << endl;
ofs << 10000 << endl;
ofs << 123.4f <<endl;

ofs.close();
return 0;
}

2 回复
#2
边城路人2007-05-10 19:52

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string>
using namespace std;

int main()
{
ofstream ofs;
ifstream ifs;
//int x;
string s;
ofs.open("data.txt");
ofs<<"Hello"<<endl;
ofs.close();
ifs.open("data.txt");
ifs>>s;
if(ifs.fail())
{
cout<<"File open fail"<<endl;
exit(1);
}
cout<<s<<endl;
return 0;
}
这样试试
通过输出流、输入流,写回文件
显示在屏幕上

#3
lblovett2007-05-11 10:48
谢谢,我的问题已解决了
1