用c++往txt文件里写文件,为什么打开txt文件什么都没有呀

来源:百度知道 编辑:UC知道 时间:2024/07/07 01:02:07
如何解决?
ofstream outfile;
outfile.open("3.txt",ios::out);
for(i=0;text[i]!='\0';i++)//往文件输出字符表
{outfile<<text[i];
}注:3.txt已建立

上代码

这段代码没什么问题,比如我这段

#include <iostream>
#include <fstream>
using namespace std;

void main()
{
chartext[]="123";
ofstream outfile;
outfile.open("C:\\1.txt");
for(int i=0;text[i]!='\0';i++)//往文件输出字符表
{outfile<<text[i];
}
outfile.close();
}

确定文件是否存在,再决定用什么函数!

outfile.close();