#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream File;
File.open("1.txt");
File << "1234556";
return 0;
}
c++向文件中写入的方法:
1.包含头文件fstream和iosteam fstream中包含类ofstream
2.用ofstream声明一个对象 ifstream
3.用open将你声明的对象和文件关联起来
4.用运算符<< >>对文件进行输入输出
//从文件中读取
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream File;
File.open("1.txt");
char *t = new char[0];
File >> t;
cout << t;
return 0;
}