题目描述
[md]
练习代码,使用`DEV`编写代码操作
```cpp
#include
#include
using namespace std;
int main(){
int age;
char name[40]; //姓名为字符串类型
ofstream fout("me.txt"); //打开文件
cin>>name>>age; // 从键盘输入
cout<
#include
using namespace std;
int main(){
int age=0; // 年龄
char name[40]={0}; // 姓名
ifstream fin("C:\小明.txt"); // 打开文件
if(fin.is_open()) {
fin>>name>>age; // 从文件读取
cout< // 用于输入输出
#include // 用于文件操作
using namespace std;
int main() {
// 创建ofstream对象,准备写入文件
ofstream myFile("E:\小猫故事.txt");
// 检查确认文件已经成功打开
if(myFile.is_open()) {
// 使用<<操作符向文件写入内容
//myFile << 3 << endl; // 后面有X行内容
myFile << "在一个阳光明媚的下午,有一只可爱的小猫在花园里玩耍。" << endl;
myFile << "小猫非常喜欢追逐蝴蝶。" << endl;
myFile << "它跑得非常快,就像一阵风。" << endl;
// 关闭文件
myFile.close();
cout << "故事已经写入文件啦!" << endl;
}else{
cout << "无法打开文件" << endl;
}
return 0;
}
```
[/md]
输入格式
输出格式
提示
[文件和流-课程中用到的素材文件.zip](/api/public/file/47e8649f9550449c9d7a28fa9052937a.zip)