跪求C++程序设计!!!!急急急急!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/29 00:57:50
从键盘输入一组字符、整数和实数后(以字符“#”结束),写入磁盘文件temp.txt中,然后从temp.txt中读出数据,并将整数和实数的累加和写入磁盘文件temp.txt的后面

你看看我写的合不合你的要求
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
char str[44];
int integer;
float flo;
cin >> str >> integer >> flo ; //从键盘输入

// 输出到文件
ofstream oFile("temp.txt");
if(!oFile)
{
cout << "打开文件失败!\n";
return 1;
}
oFile << str <<endl << integer <<endl << flo << endl;

// 从文件读入
char str2[44];
int integer2;
float flo2;
ifstream iFile("temp.txt");
if(!iFile)
{
cout << "打开文件失败!\n";
return 1;
}
iFile >> str2 >> integer2 >> flo2 ;

// 输出相加后的结果
float temp = integer2 + flo2;
oFile << temp;

oFile.close();
iFile.close();