#include <iostream>
using namespace std;
#include <fstream>//1.包含读文件
//文本文件 读文件
void test01()
{
//2.创建流对象
ifstream ifs;
//3.打开文件,并判断是否打开成功
ifs.open("test.txt", ios::in);
if (!ifs.is_open())
{
cout << "文件打开失败" << endl;
return;
}
}
int main()
{
test01();
return 0;
}
#include <iostream>
using namespace std;
#include <fstream>//1.头文件包含
//文本文件,写文件
void test01()
{
//2.创建流对象
ofstream ofs;
//3.指定打开方式
ofs.open("test.text", ios::out);
//4.写内容
ofs << "姓名:张三" << endl;
ofs << "性别:女" << endl;
ofs << "学号:20219" << endl;
//5.关闭文件
ofs.close();
}
int main()
{
test01();
return 0;
}
把这两个源文件分别放到两个项目下。要不然有两个main函数了