C++ 关于记事本的简单程序

来源:百度知道 编辑:UC知道 时间:2024/06/15 07:12:40
我想编一个C++ 根记事本有关的简单程序,要求如下:首先,新建一个叫Text1.txt的记事本文件,然后放在C:/目录下,然后随便打上几句话后保存文件, 然后按照以下要求编一个C++的程序:1: 读取Text1.txt里的内容显示在屏幕上2: 提示用户输入一段话(80字节或以下), 然后保存为一个新的文件叫Text2.txt并且保存在C:/目录下3:显示合并之后的两段话,中间用空格分开4:新建一个叫Text3.txt的文件并且保存合并之后的两段话(中间要有空格)注意: 文本必须在程序读取/写入的同时开启以及关闭, 一定按照以下格式:
有任何我讲的不清楚的地方请及时提问,谢谢~

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

int main(){
ofstream ofile;
ifstream ifile;
string t1, t2;

ifile.open("C:\\Text1.txt");
ifile >> t1;
ifile.close();

cout << endl
<< "The file Text1.txt contains the following sentence: "
<< t1
<< endl;

cout << endl
<< "Please enter another sentence to be saved on Text2.txt: ";
cin >> t2;
ofile.open("C:\\Text2.txt");
ofile << t2;
ofile.close();

t1+=" "+t2;
cout << endl
<< "The merged sentence is: "
<< t1
<< endl;
ofile.open("C:\\Text3.txt");
ofile << t1;
ofile.close();

cout << endl;
}

又不难的,我就不做了